【问题标题】:Non HTTPS URL adds extra WWW infront非 HTTPS URL 在前面添加了额外的 WWW
【发布时间】:2015-12-28 05:20:24
【问题描述】:

如果您访问Non HTTPS version,它不会重定向到 HTTPS 版本。相反,它看起来像 https://www.www.mywebsite.com 并且不起作用。这是我的 htaccess 文件中的代码。

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

【问题讨论】:

    标签: apache .htaccess http https


    【解决方案1】:

    删除 www。从这一行:

    RewriteRule .* https://www.%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    

    或者你可以这样做:

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=301,L]
    

    【讨论】:

    • 但我想保留网址前面的 www
    • 我希望这个重定向是可缓存的,所以我们不应该把 301 留在里面吗?
    • 对我不起作用,我正在添加我的网站链接,请检查。
    • 完美运行。感谢 Ryan 的快速响应和支持。
    猜你喜欢
    • 2019-12-17
    • 2014-12-16
    • 2021-10-28
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多