Forum Moderators: phranque
I am did a htaccess rewrite for some pages recently. They are working fine with the rewrite below:
RewriteCond %{HTTP_HOST} ^subdomain.mysite.com$ [NC]
RewriteRule ^(.*)-(page).htm$ [mysite.com...] [L]
This works for something like the URLs below, which is the format I would like my URLs to be in.
[subdomain.mysite.com...]
[subdomain.mysite.com...]
The problem is there are some old pages, that I would like to eventually remove and am doing a 301 redirect for currently. For example
redirect 301 /testpage.htm [westernwebstest.com...]
redirect 301 /test2page.htm [westernwebstest.com...]
The only issue I'm having is for the 301 redirects. It seems to attach the querystring.
So
/testpage.htm becomes [westernwebstest.com...]
and
/testpage.htm becomes [westernwebstest.com...]
Is there any way of preventing the query string being attached at the end?
RewriteRule ^testpage.htm$ /test-page.htm [L,R=301]
This seems to work, is this the same as using the below statement?
redirect 301 /testpage.htm [westernwebstest.com...]
Your RewriteRule in the post immediately above, needs the domain name adding to the rule target. The rule needs to fix the correct domain name, otherwise your rule redirects non-www to non-www and www to www.
If you need to clear a query string, append a question mark to the end of the target URL in the rule.
I did a htaccess rewrite for some pages recently. They are working fine with the rewrite below:RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
RewriteRule ^(.*)-(page).htm$ http://www.example.com/folder/page.php?var1=1&var2=$1 [L]
The above rule is not a rewrite. As it contains a domain name it is a redirect. As there is no [R=301] flag, it sends a 302 redirect. It redirects to a dynamic URL. Remove the domain name and add the [L] flag and turn it back into a rewrite, if that's what you need.