【问题标题】:url that includes parameters and redirection to https包含参数和重定向到 https 的 url
【发布时间】:2011-12-11 17:57:49
【问题描述】:

我在弄清楚如何仅针对包含参数的选定 url 从 http 重定向到 https(使用重写规则)时遇到问题。

例如...http://www.site.com/?action=login 应该重定向到https://www.site.com/?action=login

尝试了一些在线找到的标准重定向语法,但无法管理调整它以使用包含 url 的此类参数

谢谢

【问题讨论】:

  • 你为什么不用header('Location: https://....');?还是不合适?

标签: php mod-rewrite https


【解决方案1】:

这会将所有请求重定向到 HTTPS:

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

这将根据查询字符串内容指定更多内容:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{QUERY_STRING}     ^action=(login|foo|bar)(.*)$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

您可能需要将 [R,L] 更改为 [R,L,QSA] (QueryStringAppend),现在无法测试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-04
    • 2012-07-21
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2011-01-13
    • 1970-01-01
    相关资源
    最近更新 更多