【问题标题】:Redirect rule case insensitive重定向规则不区分大小写
【发布时间】:2014-10-31 20:52:39
【问题描述】:

我有 URL 重写规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sites/
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L]

调用此 URL 时:http://example.com/suyash

它在内部调用http://example.com/sites/suyash,但仅将URL 保留为http://example.com/suyash。请注意文件夹sites/suyash确实存在

我面临的问题是,当我调用 URL:http://example.com/Suyash(大写)时,它会显示 404 错误。

当我使用 mod_speling 模块并将以下内容添加到代码中时:

CheckSpelling On

现在当我调用 http://example.com/Suyash 时,它会将 URL 更改为 http://example.com/sites/suyash

如何让它只将 URL 从 http://example.com/Suyash 更改为 http://example.com/suyash

【问题讨论】:

  • 一旦我添加 CheckSpelling 并以错误的大小写点击 url,就会发生这种情况
  • 有可能因为文件夹sites/suyash存在而不是sites/Suyash,代码上的CheckSpelling会重定向url\
  • 但代码:RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L] 只会正常重写url
  • 好的,当你关闭CheckSpelling时会有什么行为@
  • 当 CheckSpelling 关闭时错误大小写显示 404 错误

标签: .htaccess mod-rewrite mod-speling


【解决方案1】:

我会说保持 CheckSpelling 关闭。

然后有这样的规则:

CheckSpelling Off
RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$0 -f [NC]
RewriteCond %{DOCUMENT_ROOT}/$0 -d [NC]
RewriteCond %{REQUEST_URI} !^/sites/ [NC]
RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [L]

【讨论】:

    【解决方案2】:

    mod_speling 将重定向浏览器以修正拼写,没有办法避免这种情况。我唯一能想到的就是尝试使用P 标志在内部代理请求。您需要确保已加载 mod_proxy。我还没有测试过这个:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/sites/
    RewriteRule ^([^/]+)/?(.*)$ sites/$1/$2 [NC,L,P]
    

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 2013-06-29
      • 2019-06-19
      • 2023-03-12
      • 2011-03-18
      • 2011-05-11
      • 2021-06-30
      • 2014-05-10
      • 1970-01-01
      相关资源
      最近更新 更多