【问题标题】:Apache redirect for query string查询字符串的 Apache 重定向
【发布时间】:2017-04-21 10:04:39
【问题描述】:

我有一个关于 Apache 重定向的问题。请看下面我的场景。

我有一个 URL sub.example.com,需要重定向到 www.example.com/index.php?r=something。当我在浏览器中加载www.example.com/index.php?r=something 时,css 文件将从www.example.com/css/file.css 加载。所以我不能为sub.example.com 写一个简单的重定向到www.example.com/index.php?r=something,因为它会导致css文件的404。我通过应用以下重定向规则解决了这个问题,它工作正常(意味着 css 文件也被加载)。

RewriteEngine On
RewriteRule ^(.+/?)?(/|\.htm|\.php|\.html|/[^.]*)$ http://www.example.com/index.php?r=something [P]

我现在的问题是当我输入sub.example.com/?success=1 时,它应该重定向到www.example.com/index.php?r=something&success=1。上面的规则能满足这个吗?如果不能,请您帮助相应地修改规则。提前致谢。

【问题讨论】:

    标签: apache redirect nginx administrator


    【解决方案1】:

    经过一番谷歌搜索,我找到了解决方案。有一个 QSA(查询字符串附加)标志,它将强制重写引擎将替换字符串的查询字符串部分附加到现有字符串。所以我不得不将该标志添加到现有的重写规则中,如下所示。

    RewriteRule ^(.+/?)?(/|\.htm|\.php|\.html|/[^.]*)$ http://www.example.com/index.php?r=something [P,QSA]
    

    瞧,问题解决了。

    谢谢,

    【讨论】:

      猜你喜欢
      • 2016-03-17
      • 2016-12-31
      • 2016-02-05
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多