简体   繁体   English

Apache重写所有URL,除了那些以某些路径开头的URL

[英]Apache rewrite all urls except those beginning with certain paths

I'm trying to redirect all requests except those beginning with certain paths. 我正在尝试重定向所有请求,除了那些以某些路径开头的请求。

for example, 例如,

http://www.example.com/mypath1 shouldn't redirect http://www.example.com/mypath1 不应重定向

http://www.example.com/mypath2 shouldn't redirect http://www.example.com/mypath2 不应重定向

Everything else should redirect 其他一切都应该重定向

So far ive tried getting it working using just one of the exception paths like this: 到目前为止,我已经尝试使用这样的一个异常路径使其工作:

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

and like this: 和这样:

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

and like this: 和这样:

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

However everything I try is just redirecting all requests. 但是,我尝试的只是重定向所有请求。 Does anyone know how to do this? 有谁知道如何做到这一点?

I've managed to resolve the issue, the request I was making was getting redirected later in the apache config to an error page which was then being caught by the catch all redirect. 我设法解决了这个问题,我正在制作的请求后来在apache配置中被重定向到一个错误页面,然后被catch all重定向捕获。

If anyone else is having similar issues I recommend using the apache RewriteLog as this helped pinpoint the issue. 如果其他人遇到类似问题,我建议使用apache RewriteLog,因为这有助于查明问题。 To do this just add this in your VHOST: 要做到这一点,只需在你的VHOST中添加:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM