【问题标题】:Move to https://www, when it is www or http:// or without www and http://?移动到 https://www,当它是 www 或 http:// 或没有 www 和 http:// 时?
【发布时间】:2019-06-01 15:36:04
【问题描述】:

我正在使用 Zend 框架,其中有漂亮的 url 控制器。跟随 .htaccess 是有效的,但它使 SEO 将我们视为一页的四个链接。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

我需要使用 htaccess 进行以下修复:

www.stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url

stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url

http://www.stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url

http://stackoverflow.com/nice-looking-url = https://www.stackoverflow.com/nice-looking-url

如何正确使用 htaccess?这样上面的输入网址就可以安全地使用https://www 登陆。总是在前面?

【问题讨论】:

    标签: php apache zend-framework zend-framework2 httpd.conf


    【解决方案1】:

    像这样拥有完整的 .htaccess:

    RewriteEngine On
    
    ## add www and turn on https in same rule - main domain
    RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
    RewriteCond %{HTTPS} !on
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
    
    ## turn on https in same rule - sub domain
    RewriteCond %{HTTPS} !on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    

    确保使用新浏览器测试您的更改以避免旧浏览器缓存。

    【讨论】:

    • 1 个问题。我有几个子域。应用您的版本后,除了所有子域之外的所有工作都变成这样:https://www.sms.domain.com/otherclients 而不是保持为https://sms.domain.com/otherclients
    • 所以你不想在子域之前使用 www,但在主域之前想要 www?
    • 没错。 https://www.example.comhttps://subdomain1.example.com 应保留在子域中,因为使用了一些随机 DNS 路由。
    • 当我尝试http://example.com 时,它会转到https://example.com 而不是https://www.example.com
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 2017-12-04
    • 2014-06-04
    • 2015-04-06
    • 2014-12-16
    • 2013-04-22
    相关资源
    最近更新 更多