目前,我的 htaccess 文件将所有子域的非 https 请求重定向到 https...(www 请求除外)。 IE。 http://subdomain.example.com
被重定向到 https://subdomain.example.com
(这是正确的),但 www.subdomain.example。 com
被重定向到 https://www.subdomain.example.com
(不正确)。这是我的 .htaccess 代码:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Trying to redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
最佳答案
尝试更改此设置:
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
到
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+\.example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
关于php - htaccess 将通配符子域重定向到 https(包括 www),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25899275/