www.webdeveloper.com
Results 1 to 3 of 3

Thread: [.htaccess] Rewrite url with multiple variables

  1. #1
    Join Date
    May 2007
    Posts
    8

    [.htaccess] Rewrite url with multiple variables

    Hi all,

    i'm trying to make a .htaccess file to produce some fancy urls, but i can't get it fully working.

    The problem is that i have multiple variables and different possibilities with those variables. All links are pointing to index.php, which handles the pages to load by variables in the url.

    To be more clear, i have:

    - p for page (register, home etc.)
    - cat for category
    - step for registration steps
    - maybe i'll put another variable in later on

    So there are multiple possibilities, like index.php?p=home, index.php?p=cat&cat=1 or index.php?p=register&step=2.

    I can get the .htaccess file to work for 1 and two variable, but when i put multiple rules for the different variables i can't. It looks like this right now:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?p=$1&cat=$2
    RewriteRule ^([a-z0-9_-]+)(/)?$ index.php?p=$1 [L]
    I tried to put another rule above the first rewriterule, like this:

    RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?p=$1&step=$2

    But then the combination ?p=$1&step=$2 works, but ?p=$1&cat=$2 doesn't. I can't really figure out how to get it to work. I read some tutorials, and they just told me to add another rule. Could somebody please advise me?

  2. #2
    Join Date
    May 2007
    Posts
    8
    Bump.... Can nobody help me out? Even a little bit?

  3. #3
    Join Date
    Dec 2005
    Posts
    2,984
    Place the [L] flag after the first rule. If the server matches at the first rule, it will stop.

    The [L] flag means "last" as in, if the server matches this rule, let it be the last one (don't try to match another one after it).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles