Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End get variables with mod_rewrite

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #45447
    donpeppo
    Member

    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!

    #138955
    kaffekop
    Member

    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
    )

    #138961
    CrocoDillon
    Participant

    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)
  • The forum ‘Back End’ is closed to new topics and replies.