Welcome to WebmasterWorld Guest from 220.127.116.11
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.
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! :)
Sometimes you have a programming problem and it seems like the best solution is to use regular expressions; now you have two problems.
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.
[edited by: brucew at 10:55 pm (utc) on Nov. 25, 2002]
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... :)