Dan
Dan

Reputation: 1244

Rewrite rules and 301 redirects clashing in HTaccess

I have a basic rewrite rule to turn all /pagenames/ into index.php?page=pagename

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/$ /index.php?page=$1 [L]

This works fine but I now need to redirect all the old traffic from google to the new urls. When I add the following:

Redirect 301 /pagename.php http://www.website.co.uk/pagename/

All the pages redirect to this:

http://www.website.co.uk/?page=pagename

Can somebody help me figure out why?

Thanks Dan

Upvotes: 1

Views: 98

Answers (1)

anubhava
anubhava

Reputation: 784968

You beter not mix mod_alias and mod_rewrite for this and handle all the rules via mod_rewrite itself for better control:

RewriteRule ^(pagename/?)$ http://www.website.co.uk/$1 [R=302,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/$ /index.php?page=$1 [L,QSA]

Ordering of these rules is of importance here.

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

Upvotes: 2

Related Questions