【问题标题】:Apache: How to make the same rewrite rule without using THE_REQUEST?Apache:如何在不使用 THE_REQUEST 的情况下制定相同的重写规则?
【发布时间】:2011-07-03 00:12:43
【问题描述】:

如何在不使用THE_REQUEST的情况下制定相同的重写规则?

RewriteEngine On
# Rewrite multiple slashes with single slash after domain
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR]
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L,NE]

更新: .htaccess 位置 - www.domain.com/url/.htaceess
重写操作 - www.domain.com//url/id 重写为 www.domain.com/url/id

【问题讨论】:

  • 我猜THE_REQUEST 是唯一一个变量,它包含多个前面的斜杠。所以答案:没有。
  • 不要忘记?queries——你可能不想从它们中删除斜杠。

标签: apache .htaccess mod-rewrite url-rewriting slash


【解决方案1】:

这个怎么样?

RewriteCond %{REQUEST_URI} ^(.)//(.)$ RewriteRule 。 %1/%2 [R=301,L]

拍摄from here。 (很遗憾我无法在这里测试)。

【讨论】:

  • 当 .htaccess 位于 localhost/dir/.htaccess 中时,您的重写规则将不起作用(localhost//dir/ 将返回相同)。
  • 不幸的是,这与http://domain.com///file.htm 中的 URL 开头的多个斜杠不匹配,因为这些斜杠不包含在 %{REQUEST_URI}...
  • @Floern - 你可以检查一下,我的规则工作正常,只是我想用 REQUEST_URI 而不是 THE_REQUEST 做同样的事情。
  • 我很好奇 - 如果 THE_REQUEST 满足您的需求,您为什么不想使用它?
  • @DanTup - Danny Tuppeny - THE_REQUEST 返回非拉丁 URL 的 urlencode,但我需要返回 urldecode。
【解决方案2】:

似乎没有 Apache 就没有解决方案%{THE_REQUEST}

【讨论】:

    猜你喜欢
    • 2021-12-01
    • 2018-07-15
    • 2010-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多