【发布时间】:2018-09-11 09:39:55
【问题描述】:
我在使用 https 重定向 url 时遇到问题
- www.domain.com 到 domain.com
- www.name.domain.com 到 name.domain.com
域可以,但是子域不行。
这是我的 .htaccess 代码:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,NC]
RewriteCond %{HTTP_HOST} ^www.(.+).example.com [NC]
RewriteRule ^(.*)$ http://%1\.example.com/$1 [R=301,NC]
我正在检查这个,但它不起作用:
# redirect www to none-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [QSA,R=301,L]
# redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,R=301,L]
【问题讨论】:
-
如果将
RewriteRule ^(.*)$ http://%1\.example.com/$1 [R=301,NC]更改为RewriteRule ^(.*)$ https://%1.example.com/$1 [R=301,NC]会发生什么? -
不重定向子域。并且域从 www.example.com 重定向到 www.example.com.example.com,其中第二个“example.com”在代码中:RewriteRule ^ (. *) $ http: //% 1 \ .example .com / $ 1 [R = 301,NC]
标签: apache .htaccess redirect mod-rewrite https