2017-01-03 180 views
0

给定域:重定向网址在.htaccess

http://example.com 

使用.htaccess文件,我想所有的URL重定向到除含图案的“A1”,“B1”和“C1”那几件http://example.com/dummypage.html 。例如:

http://example.com 
http://example.com/d1 

将被重定向。但是

http://example.com/a1 
http://example.com/b1 
http://example.com/c1 
http://example.com/a1/anything/... 
http://example.com/b1/anything/... 
http://example.com/c1/anything/... 

不应该被重定向。我试图在堆栈溢出中给出的其他答案之后编写规则,但没有成功。应该注意的是,其他RewriteCond和RewriteRule语句已经在.htaccess文件中声明。因此,我不知道他们是否影响重定向结果。 .htaccess文件是这样的一个:https://docs.joomla.org/Preconfigured_htaccess

回答

0

您可以在网站根目录的.htaccess使用重定向规则与负前瞻正则表达式:

RewriteEngine On 

RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+(?:a1|b1|c1|dummypage\.html)(?:/.*)?\S*\sHTTP [NC] 
RewriteRule^/dummypage.html [L,NC,NE,R=301] 
+0

它没有工作。此外,我不得不添加“dummypage.html”的正则表达式规则,以停止从浏览器“多重定向”错误。 – Daniel

+0

你的.htaccess中还有其他规则吗? – anubhava

+0

立即尝试我的更新规则。 – anubhava