【问题标题】:Apache rewrite all urls except those beginning with certain pathsApache 重写除以特定路径开头的所有 url
【发布时间】:2012-02-01 14:20:17
【问题描述】:

我正在尝试重定向所有请求,但以某些路径开头的请求除外。

例如,

http://www.example.com/mypath1 不应该重定向

http://www.example.com/mypath2 不应该重定向

其他一切应该重定向

到目前为止,我尝试仅使用如下异常路径之一使其工作:

RewriteRule ^(?!/mypath1/).*$ http://www.google.com/? [R=301,L]

像这样:

RewriteCond %{REQUEST_URI} !^/mypath1/.* [NC]
RewriteRule ^.*$ http://www.google.com/? [R=301,L]`

像这样:

RewriteCond %{REQUEST_FILE} !^/mypath1/.* [NC]
RewriteRule ^.*$ http://www.google.com/? [R=301,L]

但是我尝试的一切都只是重定向所有请求。 有谁知道怎么做?

【问题讨论】:

  • 当我将第二条规则(使用 REQUEST_URI)放入我的 vhost conf 时,它按预期工作。你确定没有其他规则在干扰吗?

标签: apache mod-rewrite url-rewriting apache2 httpd.conf


【解决方案1】:

我已经设法解决了这个问题,我发出的请求稍后在 apache 配置中被重定向到一个错误页面,该页面随后被全部捕获重定向捕获。

如果其他人遇到类似问题,我建议使用 apache RewriteLog,因为这有助于查明问题。为此,只需将其添加到您的 VHOST 中:

RewriteEngine on
RewriteLog "C:/devenv/Apache2/logs/rewrite.log"  
RewriteLogLevel 2

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-29
    • 1970-01-01
    • 2016-11-27
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    相关资源
    最近更新 更多