Parked Domain Wildcard 301 Redirects
I've got a series of domains parked on an account on a LAMP server with mod_rewrite available for duty. I'd like to achieve the following:
开发者_运维问答I'm looking for domain1.com to be the "master" - the idea is that the following redirects should be in place (with 301 statuses for maximum SEO benefit):
domain2.com redirects to domain1.com
domain3.com redirects to domain1.com domain2.com/foo/ redirects to domain1.com/foo/ domain3.com/foo/ redirects to domain1.com/foo/ domain2.com/foo/bar/ redirects to domain1.com/foo/bar/ domain3.com/foo/bar/ redirects to domain1.com/foo/bar/
And so on...
Effectively, I'd like to implement some kind of wildcard in the mix so that subpages of /foo/ and /bar/ are also redirected to the same URLs on domain1.com
I've been hunting high and low for the relevant .htaccess documentation, but can't seem to find the solution I am looking for. I was therefore wondering if any of you might have some pointers - would be very much appreciated :)
If all of your domains are parked on same host then following rules will work for you:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# handles domain2/* -> domain1/* for http
RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
# handles domain2/* -> domain1/* for https
RewriteCond %{HTTP_HOST} ^(www\.)?domain2.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://domain1.com/$1 [R=301,L]
# handles domain3/* -> domain1/* for http
RewriteCond %{HTTP_HOST} ^(www\.)?domain3.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://domain1.com/$1 [R=301,L]
# handles domain3/* -> domain1/* for https
RewriteCond %{HTTP_HOST} ^(www\.)?domain3.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://domain1.com/$1 [R=301,L]
Put them in your DOCUMENT_ROOT's .htaccess file.
For each of domain2.com and domain3.com, you want an .htaccess that looks something like:
RewriteEngine on
RewriteRule ^(.*) http://domain1.com/$1 [R=301,L]
精彩评论