SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    0 Post(s)
    0 Thread(s)

    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.


  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    19 Post(s)
    1 Thread(s)
    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):

    # 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]
    "First make it work. Then make it better."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts