views:

22

answers:

2

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?

A: 

Using a conditional Rewrite:

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

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.

Gumbo
Hm, it doesn't seem to work - I get a 404. Does it matter where the condition is placed? I mean, should it be placed on the line above the rule, or before all the rules in the file, or...?I also tried with Lekensteyn's solution without success.
Ivarska
@Ivarska: A `RewriteCond` does only belong to the first following `RewriteRule`.
Gumbo
Learning something new every day. :-) There's where I placed it first. So what could be the problem?
Ivarska
@Ivarska: Oh, I just saw that you tagged it with .htaccess. If you’re using it in an .htaccess file, you need to remove the path prefix from the pattern; in your case probably the leading `/`.
Gumbo
Problem solved - just needed to remove the slash. Thank you!
Ivarska