homepage Welcome to WebmasterWorld Guest from 54.197.130.16
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
How to redirect using wildcards in Apache
In which a n00b reveals his n00bishness
brucew




msg:1510093
 3:47 pm on Nov 25, 2002 (gmt 0)

In trying to find or figure out the answer for myself, I've RTFM (I own and have actually read the O'Reilly book), I've RTFApacheDocs, and I've trolled through the first hundred or so of the 500+ threads here on 301ís. I still need help.

Where I have the problem is that I don't understand the meanings of all the carets, parens, backslashes, brackets, braces, bangs and stuff. I finally found out the term (I think) is Regular Expressions, (took me days just to find that out because I missed it the first time through the docs). Fine. At Amazon I found a book that (foolishly) claims to be able to help me master them. But it won't be until after the holidays that I can afford a $30 book to help with one specific issue I have right now.

So, I'm asking for help here.

I need to change some directory and filenames, sending a 301 back to the UserAgent in case it's a robot (very important).

How do I say:

1) everything in old-directory is now in new-directory under the same filename.
2) For every file in this-directory (and in a separate example, in this-domain) with .htm or .html extension, use the same filename but with the .shtml extension.
3) Both rules together (old-directory/filename.htm and .html is now new-directory/filename.shtml)

There must be a far more efficient way to do this than endless hard-coded RedirectPermanent ...

Any suggestions? (Please operate under the assumption I'm completely clueless of all symbology beyond letters and numbers, because that would be very near to the truth.)

Eternal gratitude in advance.

 

DaveAtIFG




msg:1510094
 7:42 pm on Nov 25, 2002 (gmt 0)

Welcome to WebmasterWorld brucew! You've come to the right place! :)

I'm confident that one of our mod_rewrite gurus will soon post a solution for you. Until then, here's a few resources that may help you understand whatever solutions they suggest. Check out this regular expressions tutorial [gnosis.cx] and this doc [httpd.apache.org], written by the man that wrote the Apache mod_rewrite module, that offers many "real world" examples of mod_rewrite in action.

Again, welcome! :)

brucew




msg:1510095
 10:32 pm on Nov 25, 2002 (gmt 0)

Ah. Thanks Dave. For both the welcome and the resource.

Sometimes you have a programming problem and it seems like the best solution is to use regular expressions; now you have two problems.

My situation exactly! :)

The first refernce I might get through. The second one I've already ready and reread. I don't feel bad about not understanding it since in the second 'graph it says,

mod_rewrite's major drawback is that it is not easy to understand and use for the beginner.

That would be me.

[edited by: brucew at 10:55 pm (utc) on Nov. 25, 2002]

jdMorgan




msg:1510096
 10:52 pm on Nov 25, 2002 (gmt 0)

brucew,

Welcome to WebmasterWorld!

Rewrite: old-directory/filename.htm or .html to new-directory/filename.shtml

This should work...

In .htaccess :
RewriteRule ^old-directory/(.*)\.html?$ /new-directory/$1.shtml [R=301,L]

Or in httpd.conf :
RewriteRule ^/old-directory/(.*)\.html?$ /new-directory/$1.shtml [R=301,L]

Fairly efficient, I'd say... :)

HTH,
Jim

brucew




msg:1510097
 11:00 pm on Nov 25, 2002 (gmt 0)

Thanks, jd.

I shall give it a whirl presently. Giving it a quick look-see, I think there's a glimmer of understanding there.

Thanks again!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved