Forum Moderators: phranque

Message Too Old, No Replies

Redirecting many obsolete files to a single file .htaccess

.htaccess advice appreciated

         

joeduck

4:39 am on Oct 25, 2005 (gmt 0)

10+ Year Member



I need to redirect many old files to a SINGLE new file via 301 redirection but can't do it. Here's the latest attempt:

RewriteRule ^http://www.mysite.com/directory/(.*).htm [mysite.com...] [R=301,L]

SecreT2k

8:50 am on Oct 25, 2005 (gmt 0)

10+ Year Member



Try with something like this:

RewriteRule ^/directory/(.*)\.htm$ /directory/newpage.html [L]

jdMorgan

2:31 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In .htaccess per-directory context, the leading slash on the local URL-path will be stripped. So, omit that in the pattern:

RewriteRule ^directory/([^.]+)\.htm http://www.example.com/directory/newpage.htm [R=301,L]

Jim

joeduck

4:21 pm on Oct 25, 2005 (gmt 0)

10+ Year Member



Thanks to all, esp. JD - that code is working like a charm.

You are simply amazing at this stuff JD and WebmasterWorld is very lucky to have you - really appreciate the expert help.

Joe

joeduck

4:29 pm on Oct 25, 2005 (gmt 0)

10+ Year Member



One more question about this. I have about 10 different directories and need to route each to a different page. I'm planning to simply add 10 of lines to the .htaccess, one each for each directory.

Would it be better to use some form of wildcard symbol for the word "directory" and use only one line?

jdMorgan

4:34 pm on Oct 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For any directory:

RewriteRule ^([^/]+)/[^.]+\.htm http://www.example.com/$1/newpage.htm [R=301,L]

or for a list of directories:

RewriteRule ^(dir1¦dir_two¦direct3)/[^.]+\.htm http://www.example.com/$1/newpage.htm [R=301,L]

Replace the broken pipe "¦" symbols with solid pipes from your keyboard.

Also end-anchor the ".htm" with a "$" if possible.

Jim