重定向URL除外



我正在尝试在www.mywebsite/asd/下重定向所有内容,但三个URL和任何子字符,www.mywebsite/asd/A/www.mywebsite/asd/B/www.mywebsite/asd/A/

我尝试了以下模式,但似乎是错误的:

RedirectMatch 301 ^/asd/((?!A/|B/|C/).)* /asd/new-target/index.html

正则表达式执行我想要的,当我在正则编辑器中进行测试时。但是在htaccess中,它行不通。我必须更改?

您可以使用此规则:

RedirectMatch 301 ^/asd/(?!A/|B/|C/|new-target/)(.*)$ /asd/new-target/index.html

清除浏览器缓存后进行测试。确保这是您在网站root .htaccess中的第一个规则,并且/asd/目录中没有.htaccess。


另外,您可以在网站root .htaccess中使用此mod_rewrite规则:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/ads/(?:A|B|C|new-target)/ [NC]
RewriteRule ^/?asd(?:/.*)?$ /asd/new-target/index.html [L,NC,R=301]

最新更新