【问题标题】:www to non-www with SSL without index.phpwww 到非 www 使用 SSL 没有 index.php
【发布时间】:2016-05-11 18:21:39
【问题描述】:

当我尝试从网址 www.mypage.com 进入我的网站时,我得到了类似http://www.mypage.com/index.php/https://mypage.com/https://www.mypage.com....

当我从 url mypage.com 输入时,我得到了https://mypage.com - 它没问题

当我从 url mypage.com/stuff 输入时,我得到了https://mypage.com/index.php/stuff(页面正在运行)

当我从网址 www.mypage.com/stuff 输入时,我得到了https://mypage.com/index.php/stuff

我该怎么办?我想总是有像https://mypage.com 这样的网址,没有index.php,也没有'www'。

我的 .htaccess :

AddHandler application/x-httpd-php70 php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

谢谢!

【问题讨论】:

    标签: .htaccess rewrite no-www


    【解决方案1】:

    尝试切换顺序,以便最后执行到 index.php/$1 的内部重定向:

    AddHandler application/x-httpd-php70 php
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 它给出了相同的结果
    • 清除浏览器缓存并重新测试。 .htaccess 或主配置中是否还有其他可能影响结果的重写? php 本身是否进行任何 URL 操作或重定向?
    • 太棒了!这很有趣,但带有切换顺序的清晰浏览器缓存会有所帮助!谢谢!
    • 太棒了!很高兴这有效。是的,在测试重写时,使用干净的浏览器会话总是好的......例如Chrome:隐身或 IE:InPrivate..etc。对于任何 Web 开发测试来说,这都是一个好习惯。
    • 为我工作。有人可以解释一下这是如何/为什么起作用的吗?
    猜你喜欢
    • 2019-01-28
    • 1970-01-01
    • 2016-12-30
    • 1970-01-01
    • 2015-02-12
    • 2018-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-11-24
    相关资源
    最近更新 更多