Alon Gubkin
Alon Gubkin

Reputation: 57149

URL Rewriting Help

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:

http://www.example.com/baloon

to

http://www.example.com/index.php?q=baloon

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

Answers (1)

reko_t
reko_t

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

Related Questions