Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess redirect if URL contains a certain string

Tags:

.htaccess

How would I write a .htaccess redirect rule if the URL contains a certain word?

e.g. if it contains foobar then redirect to index.php

like image 782
Lee Avatar asked Jul 10 '10 18:07

Lee


2 Answers

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

or some variant thereof.

like image 115
Ignacio Vazquez-Abrams Avatar answered Sep 23 '22 16:09

Ignacio Vazquez-Abrams


RewriteRule ^(.*)foobar(.*)$ http://www.example.com/index.php [L,R=301] 

(No space inside your website)

like image 25
Farhad Avatar answered Sep 21 '22 16:09

Farhad