apache - 重定向到另一台主机时使用 [L] 标志

标签 apache mod-rewrite url-redirection

apache docs提及

You will almost always want to use [R] in conjunction with [L] (that is, use [R,L]) because on its own, the [R] flag prepends http://thishost[:thisport] to the URI, but then passes this on to the next rule in the ruleset, which can often result in 'Invalid URI in request' warnings.

现在,假设我有一个重写语句如下:

RewriteRule ^pass/?$ https://www.example.com/ [R,NC]

既然我在这里将我的客户端重定向到另一个主机/域,我真的需要传递 [L] 标志吗?

如果我也使用 [QSA] 标志会有影响吗?

最佳答案

确实是个好问题。

在我所有的测试中,我无法创建一个场景,从该规则中省略 L 会显示整体行为的任何变化。唯一的变化发生在内部,因为放置 L 标志会强制 mod_rewrite 立即运行 rewrite 循环,而不是一直运行到文件末尾。因此,如果不是出于其他原因,IMO 具有 L 是更好的性能原因。

关于QSA:这里绝对不需要,因为只有在您的规则修改QUERY_STRING 时才需要QSA > 这里不是这种情况。

关于apache - 重定向到另一台主机时使用 [L] 标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25759465/

相关文章:

php - 在 .htaccess 中的重定向链接中添加问号

apache - mod_rewrite : add trailing slash?

Centos 上的 Apache

.htaccess - 强制使用 SSL、WWW 并删除 index.php htaccess

apache - 如何在不重定向的情况下使用 mod_proxy 设置反向代理?

dns - 如何使用 https 将根域重定向到子域

apache - 如何计算每个 HTTP 请求的 CPU 使用率

wordpress - mod_rewrite 与 mod_rewrite.c,有区别吗?

php - 从根文件夹中的 htaccess 规则中排除子目录

angularjs - 将旧站点移动到 AngularJS 时管理 301 重定向