mod_rewrite, printing $1-$2 to page?

Discussion in 'PHP' started by brianj, Apr 26, 2009.

  1. #1
    Hi, simple problem:

    I created a mod_rewrite rule


    RewriteRule ^(.*)-(.*)$ index.php?keyword1=$1&keyword2=$2 [L]
    #the url i want: mysite.com/keyword1-keyword2
    
    Code (markup):

    How can i make that these 2 variables are printed out on access?

    something like:
    echo $1;
    echo $2;


    ??

    Thanks for help
     
    brianj, Apr 26, 2009 IP
  2. MakeADifference

    MakeADifference Peon

    Messages:
    476
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    RewriteRule ^([^.]+)-([^.]+)$ index.php?keyword1=$1&keyword2=$2 [L]

    OR

    RewriteRule ^(.*?)-(.*?)$ index.php?keyword1=$1&keyword2=$2 [L]
     
    MakeADifference, Apr 26, 2009 IP
  3. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    hey thanks,

    i think the problem is on the php side:

    <? 
    print $1;
    print $2;
    ?>
    PHP:
    .. how can i read these 2 variables mysite.com/keyword1something-keyword2something ??


    All i want is to have them printed as:

    keyword1something
    keyword2something
     
    brianj, Apr 26, 2009 IP
  4. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #4
    You've to echo $_gets:
    echo 'keyword1: '.$_GET['keyword1'].'<BR />keyword2: '.$_GET['keyword2'];
    PHP:
    Regards
     
    koko5, Apr 26, 2009 IP
  5. brianj

    brianj Member

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    yeah awesome, that's it! thanks!!! :)
     
    brianj, Apr 26, 2009 IP