Reputation: 33
I'm not very experienced with htaccess. today I fail in writing an .htaccess to rewrite a url.
What I want: My project is hosted on a subdomain e.g. sub.domain.com
My htaccess should manage:
sub.domain.com
should redirect to www.domain.com
(Redirect 301, that's clear)sub.domain.com/test
to www.domain.com?var=test
/admin
shouldn't be redirectedThanks in advance for tips!
Upvotes: 3
Views: 322
Reputation:
This should do it for you:
RewriteEngine on
RewriteCond %{HTTP_HOST} =sub.example.com
# Following condition added to support changed requirement, see comments
RewriteCond %{QUERY_STRING} !(?:^|&)var=
RewriteCond %{REQUEST_URI} !^/admin/
RewriteRule ^(.*)$ http://www.example.com/?var=$1 [R=301,L]
This will drop any query string that was in the original request. If you want to keep any query string, and just append 'var=...' to it, then add QSA
to the flags at the end of the last line, separated by a comma.
Upvotes: 2