【问题标题】:Switching http to https using mod_rewrite使用 mod_rewrite 将 http 切换为 https
【发布时间】:2013-02-19 12:59:52
【问题描述】:

我知道有很多类似的问题,但是我花了2天多的时间调查它没有成功,所以你是我最后的希望)

我写了以下重写规则:

RewriteCond %{HTTPS} off [NC]
RewriteCond %{REQUEST_URI} ^((/member/settings)?/orders/?)$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]

RewriteRule \.(gif|jpe?g|png|css|js|eot|woff|ttf|svg)$ - [NC,L]

RewriteCond %{HTTPS} on [NC]
RewriteCond %{REQUEST_URI} !^((/member/settings)?/orders/?)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

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

我希望 URL example.com/orders/example.com/member/settings/orders/ 始终重定向到 HTTPS,而所有其他 URL 都强制使用 HTTP。此外,所有查询都应转发至index.php。 而且,显然,所有媒体文件都应保持与请求相同的协议。

当我首先请求http://example.com/orders/ 时,它会重定向到https://example.com/orders/,然后第二次重定向到http://example.com/index.php?/orders/。实际上是预期的,但问题是“index.php”出现在浏览器的地址栏中。

问题是如何去掉浏览器地址栏中的'index.php'?

任何帮助将不胜感激。

【问题讨论】:

    标签: http mod-rewrite https


    【解决方案1】:

    然后第二次重定向到http://example.com/index.php?/orders/ ....我不知道'index.php'从哪里出现在URL中...

    因为您有一个 RewriteRule 可以做到这一点:

    RewriteRule ^(.*)$ index.php?/$1 [NC,QSA,L]
    

    不确定您要在该块中完成什么,但请尝试摆脱它。

    【讨论】:

    • 感谢您的回复。我需要在 index.php 中执行所有请求,这就是我需要该规则的原因。问题是“index.php”出现在浏览器的地址栏中。
    猜你喜欢
    • 2015-12-07
    • 2013-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-13
    • 2010-09-20
    • 2017-02-18
    • 1970-01-01
    相关资源
    最近更新 更多