mod_rewrite URL - URL parameters not registering ..?

Discussion in 'Apache' started by xxkylexx, Oct 12, 2008.

  1. #1
    Hey guys,
    I am using the following to rewrite URL's for a user's image gallery:

    Want to achieve:
    http://www.domain.com/gallery/xxkylexx/
    Code (markup):
    RewriteRule ^gallery/([^/\.]+)/?$ gallery.php?username=$1 [L]
    Code (markup):
    This works fine. However, whenever I add additional URL parameters, my PHP code is not detecting them at all.

    For example:

    http://www.domain.com/gallery/xxkylexx/?folder=12
    Code (markup):
    if(isset($_GET['folder'])) echo 'folder param set';
    else echo 'folder param not set';
    PHP:
    Will return

    Same thing happens with my pagination parameter:
    http://www.domain.com/gallery/xxkylexx/?page=2
    http://www.domain.com/gallery/xxkylexx/?folder=12&page=2
    Code (markup):





    If I do not use my my-rewrite version of the URL, the script works fine.

    http://www.domain.com/gallery.php?username=xxkylexx&page=2
    http://www.domain.com/gallery.php?username=xxkylexx&folder=12&page=2
    Code (markup):
    Any ideas? Thanks in advance!
     
    xxkylexx, Oct 12, 2008 IP
  2. Ladadadada

    Ladadadada Peon

    Messages:
    382
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Modify the rewrite rule so that it looks like this:
    RewriteRule ^gallery/([^/\.]+)/?$ gallery.php?username=$1 [QSA,L]
    Code (markup):
    The difference is the QSA at the end in the square brackets. QSA stands for "Query String Append". It makes sure that any query strings (The part after the question mark) are correctly added on to the rewritten URL. It will also substitute an ampersand (&) for a question mark (?) if there is already a question mark in the URL.
     
    Ladadadada, Oct 14, 2008 IP
  3. xxkylexx

    xxkylexx Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Lada,
    Thanks for the info. That did the trick!
     
    xxkylexx, Oct 14, 2008 IP