Forum Moderators: phranque

Message Too Old, No Replies

Infinite loop with slash before query

         

famouswebteam

4:09 pm on May 18, 2010 (gmt 0)

10+ Year Member



Hello, I am experiencing an infinite loop when a slash is placed in the url before the query string.

This works perfectly fine: www.site.com/reviews?something=else

This however, goes into an infinite loop: www.site.com/reviews/?something=else

I cant figure out why its doing it in the first place, or how to correct it.

I tried removing the slash on that specific url if there isn't one:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/reviews/$
RewriteRule (.*)$ [site.com...] [R=301,QSA,L]

And that seems to take out the slash only if there is no query string. So www.site.com/reviews/ would rewrite to www.site.com/reviews. But if there are any variables in the URL, it leaves the / in there.

Any ideas?

Thanks!


Update:

Doing this

RewriteCond %{REQUEST_URI} ^/reviews/$
RewriteCond %{QUERY_STRING} !=""
RewriteRule (.*)$ [site.com...] [R=301,QSA,L]

Seems to have removed the / when there is a query. Not sure if that is 100% correct though.

g1smd

4:39 pm on May 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What is the code supposed to DO? You haven't explained why this code exists at all.

Once we know what it is supposed to do, we can point out how the code you have now, differs from the code that would do what you want it to.

I suspect the (.*) pattern should be something else, but there's other potential issues.

Should the redirect clear or retain the appended query string?

The 'exists' checks are very inefficient. At least one additional RewriteCond is needed here I suspect.