[英]Redirect all but one file in a directory via httpd.conf / htaccess
I would like to redirect as such... 我想重定向......
http://old.com/a/b/ -> http://new.com/y/z/
http://old.com/a/b/file.php -> http://new.com/y/z/
http://old.com/a/b/c/file.php -> http://new.com/y/z/
http://old.com/a/b/anything -> http://new.com/y/z/
http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.php
I currently have the following in httpd.conf and it redirects correctly: 我目前在httpd.conf中有以下内容,它正确地重定向:
RedirectMatch 301 /a/b/(.*) http://new.com/y/z/
I don't know how to exclude one file from being redirected. 我不知道如何排除一个文件被重定向。
Basically I want all URL's starting with "old.com/a/b/" to go to a singe new URL, except I want a single URL to be ignored. 基本上我希望所有以 “old.com/a/b/” 开头的 URL都转到一个新的URL,除了我想要忽略一个URL。
Using a negative lookahead in the regular expression should work: 在正则表达式中使用否定前瞻应该有效:
RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/
If you want the rest of the path to carry over with the redirect, use the backreference $1 as in: 如果您希望路径的其余部分继续使用重定向,请使用后向引用$ 1,如下所示:
RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/$1
I know it's been answered but for people who want some RewriteRule stuff: 我知道它已被回答,但对于想要一些RewriteRule的人来说:
http://old.com/a/b/ -> http://new.com/y/z/
http://old.com/a/b/file.php -> http://new.com/y/z/
http://old.com/a/b/c/file.php -> http://new.com/y/z/
http://old.com/a/b/anything -> http://new.com/y/z/
http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.php
This should work: 这应该工作:
RewriteCond %{HTTP_HOST} ^old\.com [NC]
RewriteCond %{REQUEST_URI} !^(/a/b/EXCLUDE\.php) [NC]
RewriteRule /a/b/(.*) http://new.com/y/z$1 [QSA,NC,R=301]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.