Recent Topics

1 Jul 31, 2004 04:15    

I'm after a bit of help with 301 redirects if possible please. I have a lot of static html pages that I am moving and changing to php e.g.:

/oldlocation/folder/index.html becomes /newlocation/index.php
/oldlocation/folder/page.html becomes /newlocation/page.php

I could use Redirect 301, but there are about 300 pages so I'm hoping there's an easier way. Could anyone assist with this please?

Thanks
Stuart

2 Jul 31, 2004 05:30

Sounds like a good time to use mod_rewrite. Something like this should work.

RewriteEngine On
RewriteRule ^oldlocation/folder/(index|page)\.php /newlocation/$1.php

What this essentially says is if part of the URI is /oldlocation/folder/ and has either index.php or page.php then map it to /newlocation with whatever.php. If you'd like your visitors to know about the redirect then add [R] afterward like this which will write the redirect to the address bar.

RewriteRule ^oldlocation/folder/(index|page)\.php /newlocation/$1.php [R]

3 Jul 31, 2004 11:03

Thank you, that's worked a treat. I replaced the page names with .* and added [R=301] to show it as a permanent redirect, and it's working exactly as I wanted. That's saved me a couple of hours work, cheers.


Form is loading...