Reputation: 57149
I'm trying to learn Regex & URL Rewriting in PHP. How can I create an .htaccess file which will rewrite (not redirect) any url to index.php?q={url}
?
For example:
to
I tried:
RewriteEngine On
RewriteRule ^$ index.php?q=$1 [R]
...but it is not working. What am I doing wrong?
Thanks.
Upvotes: 0
Views: 219
Reputation: 56450
Rewriting ANY url to index.php?q=$1 would result in internal server error as it'd create an endless loop; instead do something like this:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteRule ^(.*)$ index.php?q=$1 [L]
Upvotes: 3