Forum Moderators: phranque
A RewriteRule only 'sees' information before a query string (stuff after the ?). To test for a query string, you have to use a condition. The looping problem stems from this, because the RewriteRule never sees that there is the necessary information after the ?.
To break the looping, you will need to test to see if there is a query string exist and if so, exit:
RewriteCond %{QUERY_STRING} !^.
RewriteRule ^index\.html$ index.html?lang=en [L]
OR, for this:
from /foo or /foo/index.php or /foo/
to index.php?cat=foo
In the 'root' .htaccess file:
RewriteCond %{QUERY_STRING} !^.
RewriteRule ^foo(/(index\.php)?)?$ /index.php?cat=foo [L]
The Condition:
! = is not
^ = begin the line
. = any character, that is not the end of a line.
($) left off to use the implicit 'and anything else'
The Left Side of the Rule:
^foo(/(index\.php)?)?$
^ = begins the line
(/ = begin 1st grouping to make the / optional
(index\.php) = full 2nd grouping to make index\.php optional
? = 0 or one of the preceding characters or groups
)? = close the 1st group and make both groups optional
$ = ends the line
The Right Side of the Rule:
/ = A rewrite issues a new request to the server, so a preceding / is required
index.php?cat=foo = where we want to go
[L] = if this rule qualifies, stop processing now (should always be included, unless you are absolutely certain you should not have it.)
At times it is necessary to use the QSA (Query String Append) 'flag' or 'directive', which lets Apache 'know' it should append, or re-append more information to the rewrite. This would change [L] to [QSA,L]
Hope this helps.
Justin
RewriteCond %{QUERY_STRING}!^.
RewriteRule ^index\.html$ [fullpath.com...] [QSA,R]