php - htaccess 将通配符子域重定向到 https(包括 www)

标签 php apache .htaccess mod-rewrite redirect

目前,我的 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/

相关文章:

php - 我怎样才能检测到 "Slashdotted"并存活下来?

java - 公共(public)资源池 : How to instantiate a concrete pool?

javascript - 在 Javascript/XMLHttpRequest 中保持连接

php - 管理面板的 htaccess 重写规则

php - ORDER BY 两个日期mysql查询

PHP MySQL : boolean Value works on local server but returns empty on live server?

php - 内部连接数据库

PHP 配置文件更新错误 mysql_num_rows

linux - 禁用 http 端口上的 telnet?

.htaccess - 共享主机上的 symfony2