Ivar
Ivar

Reputation: 4392

htaccess: Rewrite collision - simple question

This row will certainly cause a little collision as it will try to rewrite the goal itself:

RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]

Now, how do I prevent this?

Upvotes: 1

Views: 78

Answers (2)

Gumbo
Gumbo

Reputation: 655319

Just add a condition that the matched string is not the same as the destination:

RewriteCond $1 !=page.php
RewriteRule ^/(.*)$ page.php?q=$1 [L]

Here the != in RewriteCond indicates a negated lexicographic comparison instead of the implied regular expression comparison.

Upvotes: 2

Lekensteyn
Lekensteyn

Reputation: 66425

Using a conditional Rewrite:

RewriteCond %{REQUEST_URI} !^page.php?
RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]

Upvotes: 0

Related Questions