I am facing problems when creating a 301 redirect on my site. When I am creating a redirect the browser is showing the full qherysting rather than directing the page.
eg. I am wanting to direct /contact to /contact-us
What I am getting is:
/contact-us?page=contact
Here is the code from my .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteBase /
redirect 301 /contact /contact-us
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
Any ideas why this is happening?
This is a mod_alias/mod_rewrite conflict. The path processing pipeline is handling the 2 things separately. You can just stick with mod_rewrite and replace
with
So the rewriting will stop once it gets here and the last rule never gets applied. Otherwise, mod_alias will redirect the URL, but not until it’s run the URI through mod_rewrite, thus you get this globbed together redirect. If you don’t mind a trailing ?, you could also add it to the end of your redirect target:
so that the query string won’t get appended.