如果网址包含一些单词,则重定向网址

时间:2014-03-29 16:41:07

标签: .htaccess redirect

我喜欢htaccess将包含一些单词的网址重定向到主页

示例:

重定向

www.mywebsite.com/folder/dont-stop-the-fun
www.mywebsite.com/folder/dont-fun-stop-the
www.mywebsite.com/folder/play-the
www.mywebsite.com/folder/dont-fun-give-the

www.mywebsite.com /

上面的示例重定向任何包含fun,play& amp;的url。给主页

我找到了

RewriteCond %{REQUEST_URI} foobar
RewriteRule .* index.php

但它只重定向一个单词

感谢

2 个答案:

答案 0 :(得分:1)

您可以在root .htaccess中使用此规则:

RewriteEngine on

RewriteRule ^folder/(dont-stop-the-fun|dont-fun-stop-the|play-the|dont-fun-give-the) /index.php? [L,NC,R=301]

答案 1 :(得分:0)

以下内容应达到您的目标

RewriteEngine on
RewriteCond %{REQUEST_URI} dont-stop-the-fun [OR]
RewriteCond %{REQUEST_URI} dont-fun-stop-the [OR]
RewriteCond %{REQUEST_URI} play-the          [OR]
RewriteCond %{REQUEST_URI} dont-fun-give-the
RewriteRule .* /index.php [R]

以上内容将重定向任何包含字符串的网址。

e.g。以下网址:

http://example.com/dont-fun-give-the

http://example.com/dddd/ddd/ss/aa/dont-fun-give-the

http://example.com/hello-dont-fun-give-the

http://example.com/dont-fun-give-the-dog

将全部重定向到:http://example.com/index.php