【问题标题】:Combine htaccess rewrites结合 htaccess 重写
【发布时间】:2012-08-29 21:20:14
【问题描述】:

我正在使用 php CodeIgniter 并且在我的 .htaccess 文件中有以下重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

由于我希望用户通过 SSL 使用网站,我想添加以下重写规则:

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

但是,当我这样做时,子目录中的每个页面都会有 /index.php/actual_page - 之前的 index.php 是不需要的。我认为这可能是因为里面有RewriteRule ^(.*)$ index.php/$1 [L],但是没有RewriteRule ^(.*)$ @987654321@$1 [R,L] 它可以正常工作。

那么,如何在不破坏第一次重写的情况下将 url 重写为 https?

【问题讨论】:

    标签: php .htaccess url url-rewriting


    【解决方案1】:

    确保 https 重定向发生在重写 index.php 之前。你希望它看起来像这样:

    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://www.link.com/$1 [R,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 完美!做到了。谢谢你,乔恩!
    猜你喜欢
    • 2011-11-19
    • 2017-04-12
    • 2011-01-26
    • 2014-10-01
    • 2013-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-26
    相关资源
    最近更新 更多