通过httpd.conf文件/ htaccess的重定向目录中的所有,但一个文件 [英] Redirect all but one file in a directory via httpd.conf / htaccess

查看:115
本文介绍了通过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

我目前有在httpd.conf以下,并重定向正确的:

I currently have the following in httpd.conf and it redirects correctly:

RedirectMatch 301 /a/b/(.*) http://new.com/y/z/

我不知道如何从被重定向排除一个文件。

I don't know how to exclude one file from being redirected.

基本上,我希望所有的URL的开始old.com/a/b/去单张新的URL,但我想忽略一个单一的URL。

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.

推荐答案

在常规EX pression使用负向前查找应该工​​作:

Using a negative lookahead in the regular expression should work:

RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/

如果你想要的路径的剩余部分结转的重定向,使用反向引用$ 1中的:

If you want the rest of the path to carry over with the redirect, use the backreference $1 as in:

RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/$1

这篇关于通过httpd.conf文件/ htaccess的重定向目录中的所有,但一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆