2015-07-10 219 views
1

除了一个外部URL的所有目录的URL我需要重定向如下:重定向使用的.htaccess

http://olddomain.com/products/ * --->http://shop.newdomain.com/

除了http://olddomain.com/products/certain-category

到目前为止,我可以重定向他们都:

RedirectMatch 301 /products(.*) http://shop.newdomain.com/ 

我只需要停止重定向“某些类别”?

喜欢的东西:

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/
RewriteCond /products(.*) !^/(certain-category)/ 
RewriteRule (.*) http://shop.newdomain.com/ [L,R=301] 
</IfModule> 

虽然这是整个网站重定向到http://shop.newdomain.com/

回答

1

您可以使用该负前瞻基于规则:

RewriteEngine On 

RewriteRule ^products/(?!certain-category).*$ http://shop.newdomain.com/ [NC,L,R=301] 

(?!certain-category)是负先行即会如果certain-category正好在URL中的/products/后面,则不能匹配。

确保在测试之前清空浏览器缓存。

+1

谢谢,完美的工作:) –