Reputation: 280
I like to htaccess redirect a url that contains some set of words to homepage
Example:
redirect
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
to
www.mywebsite.com/
The example above redirects any url that contains fun,play & give to homepage
I have found
RewriteCond %{REQUEST_URI} foobar
RewriteRule .* index.php
but it redirects only one word
thanks
Upvotes: 3
Views: 2003
Reputation: 786091
You can use this rule in 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]
Upvotes: 1
Reputation: 12469
The following should achieve what you are looking for
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]
The above will redirect any url that contains the string anywhere in it.
e.g. The following urls:
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
will all be redirected to: http://example.com/index.php
Upvotes: 0