Reputation: 2425
I got a subdomain http://sub.domain.com
I want all links from this subdomain be redirected to a target domain with www, nonwww and also redirect the path.
REDIRECT:
www = http://www.sub.domain.com
nonWww = http://sub.domain.com
path = http://sub.domain.com/something/anything
to TARGET:
http://www.domain.com/sub/zero
What is the .htaccess for this?
What would be the change if i don't want to transport the path to the new target, so have a static target?
Upvotes: 2
Views: 9282
Reputation: 786031
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
# target with original URI being carried over
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/sub%{REQUEST_URI} [NE,R=301,L]
And for 2nd part:
# static target
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/sub/zero [NE,R=301,L]
Upvotes: 6