Grow your CSS skills. Land your dream job.

get variables with mod_rewrite

  • # June 11, 2013 at 10:52 am

    this is my .htaccess:

    RewriteRule ^([^/]*)(.*) index.php?page=$1&var1=$2&var2=$3 [QSA,L]

    example of my problem:

    echo ‘page: ‘ . $_GET;

    echo ‘var1: ‘ . $_GET;

    echo ‘var2: ‘ . $_GET;

    echo ‘var:3 ‘ . $_GET;

    Url : domain.com/page1/asd/123/d2d

    output:

    page: page1

    var1: asd123d2d

    var2: *empty*

    var3: *empty*

    So as you can see the / wont separate the *vars* so i would like some help with that :)

    Thanks for any help you can provide!

    # June 16, 2013 at 4:58 pm

    Do you have var1 – 3 on all pages ?

    If not I would just rewrite to **index.php?page=$1** and then make php deal with the rest

    $uri = $_GET;
    $has = explode(“/”, $uri );
    print_r( $has, true );

    Url : **domain.com/page1/var1/var3/zxy/more-here** =

    Array
    (
    [0] => pageX
    [1] => a
    [2] => b
    [3] => zxy
    [4] => more-here
    )

    # June 16, 2013 at 7:01 pm

    I don’t know much about how .htaccess works with regular expressions but `^([^/]*)(.*)` reads to me as ‘start of string, capture anything without a slash, capture anything that follows’, which are exactly the 2 captures you’re getting.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".