Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect query string with mod_rewrite (vice versa)

Suppose I have URL's with query string, ie: /DesignPatterns

Using mod_rewrite, how can I redirect them to: /index.php?book=DesignPatterns

is it correct the following?

 RewriteCond %{QUERY_STRING} (\w+) 
 RewriteRule ^index.php?book=%1? [L,R=301]

PS: The original question: How can I match query string variables with mod_rewrite? (Feb 12 '10, Patrick McElhaney, I am asking following his permission)

like image 563
deb Avatar asked Nov 07 '22 08:11

deb


1 Answers

The complete solution would be

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+) index.php?search=$1 [L]
like image 137
Shahzad Fateh Ali Avatar answered Nov 28 '22 02:11

Shahzad Fateh Ali