SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite for Pretty URL and Query String

    I am retooling my URL to be part Pretty URL and part Query String to make it more SEO friendly.

    In the past, my URL looked like this...
    Code:
    www.debbie.com/finance/economy/
    And my mod_rewrite looked like this...
    Code:
    RewriteRule ^([^/]+)/([^/]+)/$ articles/index-subsection.php?section=$1&subsection=$2 [L]

    If someone decides to navigate to a different page, or perform a sort, then the URL above will change to something like this...
    Code:
    www.debbie.com/finance/economy/?page=2&sortname=by-date&sortdir=desc

    If I leave my mod_rewrite as it used to be, then I can have this new URL, but the $_GET variables appear to be blank.


    How should I adapt my mod_rewrite so it works for either type of URL??


    Sincerely,


    Debbie

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,313
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    By changing [L] to [L,QSA]

    http://httpd.apache.org/docs/2.4/rew....html#flag_qsa
    "When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined."
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,931
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    By changing [L] to [L,QSA]

    http://httpd.apache.org/docs/2.4/rew....html#flag_qsa
    "When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined."
    You beat me to the punch!

    I tried this and it seems to be working...
    Code:
    RewriteRule ^([^/]+)/([^/]+)/$ articles/index-subsection.php?section=$1&subsection=$2 [L,QSA]
    Thanks!!


    Debbie


Bookmarks

Posting Permissions

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