0
我想如果域匹配也非www到www所有域非HTTPS重定向到https。htaccess的條件重定向如果域匹配
這裏是我的代碼,它的工作原理除了它不會將非www重定向到僅限https版本的www。
注意:我分離非www和www版本的規則,因爲如果我在url中添加www,它會廣告www 2 x。
RewriteEngine On
#all non-www to www (without HTTPS)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#non-https to https if these 2 domains matched - and since there is already www don't add it.
RewriteCond %{HTTP_HOST} ^www\.domainA\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.domainB\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
#non-https to https if these 2 domains matched - and also www
RewriteCond %{HTTP_HOST} ^domainA\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^domainB\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*)$ index.html
什麼不起作用? – anubhava
@anubhava如果我訪問https:domainA.com它不會將www添加到它。 –