Infinite loops scenario

I wanted to add a simple piece to the query string of a url.

Had trouble matching ls-home using ^ls-home$

Q1 is the hyphen special I tried escaping it with a backslash and it still didnt find it. What worked was in the below.

Here is the infinite loop scenario

RewriteCond %{REQUEST_URI} ls-home
RewriteRule ^(.*)$ [L]

On the one hand I can see that ls-home would get matched again the second time round if the htaccess page gets reloaded ? some kind of loop. On the other hand it sounds reasonable to be able to do this.


The hyphen is sometimes special – only when inside a character class. Your use of it should be fine.

I’m not clear on all the requirements for this problem, so we’ll need to clear up some things first. You want to add a query string to the URL. Any URL? Or only /ls-home URLs? Do the values in the query string derive from the path? Do you want to do an external redirect (visible to the browser) or an internal rewrite?

With my incomplete information, here’s something you could try (untested):

[FONT=Courier New]# if “pres=ls” is not in the query string
RewriteCond %{QUERY_STRING} !(?:^|&)pres=ls(?:$|&)

then add it, while allowing the path to pass through unchanged, and send a redirect response to the browser

RewriteRule (.*) $1?pres=ls [QSA,R][/FONT]