views:

259

answers:

2

I have a site with URLs like this:

http://domain.co.uk/subdir/page.php

I have redesigned the site so URLs are now like this:

http://domain.co.uk/page.php

How can I 301 redirect all the pages to their new locations using Apache's mod_rewrite?

+3  A: 

Something like this should do the trick, I believe:

RewriteRule ^subdir/(.*)$ http://domain.co.uk/$1 [R=301,QSA,L]
ceejayoz
+4  A: 

This should do the trick:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^subdir/(.*)$ http://domain.co.uk/$1 [R=301,L]
</IfModule>

Update: Tested it, it works.

Is the full URL really needed? Seems like "RewriteRule ^subdir/(.*)$ /$1 [R=301,L]" should do the trick too.
PEZ
@PEZ - it's not a bad idea to canonicalise the domain, and that's a side effect of doing the config this way
Gareth