I need to redirect all subdomain requests to be redirected to my primary domain in my htaccess. I need it to also include some sort of wildcard redirect.
e.g. washington.mysite.com/ redirect to mysite.com/washington
but I need to to also redirect any old url on the subdomain to mysite.com/washington
e.g. washington.mysite.com/category.aspx?washington-attractions&CatID=17 redirect to my-site.com/washington
This is my code so far:
RewriteCond %{HTTP_HOST} ^washington\.mysite\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.washington\.mysite\.com$
RewriteRule ^(.*)$ "http\:\/\/www\.mysite\.com\/washington/$1" [R=301,L]
However it still appends the old URL to the new one
e.g. washington.mysite.com/category.aspx?washington-attractions&CatID=17 redirects to my-site.com/washington/category.aspx?washington-attractions&CatID=17
Basically I need the redirect washington.mysite.com/*(anything) to my-site.com/washington
Any suggestions would be much appreciated :)
RewriteCond %{HTTP_HOST} ^(www\.)?washington\. [NC]
RewriteRule ^(.*)$ http://www.mysite.com/washington [R=301,L]
In your RewriteRule you have /$1 which matches the (.*) wildcard set of parentheses. This is why you're getting the path from the old URLs appended.
I combined your 2 RewriteCondition's, making the (www\.) match optional with ?.
The [NC] flag is the nocase flag.
To clear the querystring, append ? to the end of the rewrite URL
RewriteCond %{HTTP_HOST} ^(www\.)?washington\. [NC]
RewriteRule ^(.*)$ http://www.mysite.com/washington? [R=301,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With