.htaccess redirect secondary domain to primary dom

2019-08-08 08:21发布

I am wanting to redirect my secondary domain to my .com primary domain, such that when I visit domain.asia or www.domain.asia it redirects the URL to https://www.domain.com. The problem I am having is that the redirect goes to https://www.domain.asia (not the .com) and the .asia domain does not have a security certificate and because of this shows a warning.

How can I visit domain.asia and have it redirected to https://www.domain.com?

The secondary domain is parked on the same server as the primary domain. Here is my .htaccess file:

# redirect to .com
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.asia$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

# redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect to https if not
RewriteCond %{HTTPS} !=on
rewritecond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

1条回答
Bombasti
2楼-- · 2019-08-08 09:04

You have to use:

# redirect to .com
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [OR,NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.asia$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

with OR, Use this to combine rule conditions with a local OR instead of the implicit AND.

查看更多
登录 后发表回答