简体   繁体   English

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

[英]htaccess Redirect Wildcard Subdomains to https (Including www)

Currently my htaccess file redirects non-https requests for all of my subdomains to https... except for www requests. 目前,我的htaccess文件将所有子域的非https请求重定向到https ...除了www请求。 Ie http://subdomain.example.com gets redirected to https://subdomain.example.com (this is correct) but www.subdomain.example.com get redirected to https://www.subdomain.example.com (not correct). http://subdomain.example.com被重定向到https://subdomain.example.com (这是正确的),但www.subdomain.example.com被重定向到https://www.subdomain.example.com (不正确)。 Here's my .htaccess code: 这是我的.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>

Try changing this: 尝试改变这个:

RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

to

RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+\.example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM