我想重定向所有的HTTP和HTTPS协议的要求,这些网址被重定向到https://www.example.com
:别名htaccess的通配符重定向HTTP和HTTPS请求
example.com
example.com.au
www.example.com.au
example.co.nz
www.example.co.nz
example.co.uk
www.example.co.uk
example.net
www.example.net
example.net.au
www.example.net.au
example.org
www.example.org
我尝试这样做第一,但它不” t重定向https协议请求的网址。
RewriteCond %{HTTP_HOST} ^example.com [OR]
RewriteCond %{HTTP_HOST} ^example.com.au [OR]
RewriteCond %{HTTP_HOST} ^www.example.com.au [OR]
RewriteCond %{HTTP_HOST} ^example.co.nz [OR]
RewriteCond %{HTTP_HOST} ^www.example.co.nz [OR]
RewriteCond %{HTTP_HOST} ^example.co.uk [OR]
RewriteCond %{HTTP_HOST} ^www.example.co.uk [OR]
RewriteCond %{HTTP_HOST} ^example.net [OR]
RewriteCond %{HTTP_HOST} ^www.example.net [OR]
RewriteCond %{HTTP_HOST} ^example.net.au [OR]
RewriteCond %{HTTP_HOST} ^www.example.net.au [OR]
RewriteCond %{HTTP_HOST} ^example.org[OR]
RewriteCond %{HTTP_HOST} ^www.example.org
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
我接下来尝试了这个,但它没有重定向其中有www
的网址。
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
如何使用,从所有别名域名在两个HTTP重定向URL的通配符和HTTPS来https://www.example.com
?
UPDATE:
重写规则的试验与!
通配符按如下@CBroe评论:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC,OR]
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
更新2:
继@starkeen评论,因为我想要将http和https请求重定向到上述url,我在我的htaccess中添加了2套url。第一个是重写所有的HTTP到HTTPS,第二个重定向,如果它不符合上述网址:
# Force to use HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule^https://www.example.com%{REQUEST_URI} [NE,L,R]
使用一个单一的条件来检查主机是_不是'www.example.com' ...? – CBroe
这可能更容易。你能给我一个样品吗? – Neel
你可以使任何RewriteCond模式与一个不匹配的模式进行预先匹配,使用'!',http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond – CBroe