mod_rewrite---- yet some ?var=1 :(

Discussion in 'Site & Server Administration' started by trixs, Jul 16, 2007.

  1. #1
    Hey Everyone,

    Lets say I have a domain such as:

    www.#.com/index.php?cat1=1&cat2=1

    said domain is rewritten to:

    www.#.com/index/1/2/

    with this mod_rewrite:

    Options +Indexes
    Options +FollowSymlinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^index/(.*)/(.*)/(.*)$ index.php?cat1=$1&cat2=$2&cat3=$3 [L]
    RewriteRule ^index/(.*)/(.*)$ index.php?cat1=$1&cat2=$2 [L]
    RewriteRule ^index/(.*)$ index.php?cat1=$1 [L]


    Now as you see can have up to three categorys in this example..
    Lets say I wish to add this to the end of the domain:

    ?rows=3

    so a domain would be like this in the url

    www.#.com/index/1/2/?rows=3

    How do I do this? I need to inorder for the website to be interactive -- for instance 3 would be how many of rows to show.. This could also be anything. I want to be able to add this ?rows whenever.

    Any idea how to do this without making mod_rewrite see ?rows=3 as a cat1,cat2, or cat3??

    I really need help with this one so if I am not explaining myself please let m know.. I do have a prlbem with that :eek:

    Thanks,

    Trixs!
     
    trixs, Jul 16, 2007 IP
  2. WebGeek182

    WebGeek182 Active Member

    Messages:
    510
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    95
    #2
    You could have a rewritten url like:

    www.#.com/index/1/2/r/3/

    or

    www.#.com/index-1-2-r-3.html
     
    WebGeek182, Jul 16, 2007 IP
  3. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Heres the only way I can think to accomplish this:

    I would have to make the url look like:

    www.#.com/index/cat1/1/cat2/2/rows/3

    then just use a mod_rewrite such as

    RewriteRule ^index/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)$ index.php?$1=$2&$3=$4&$5=$6 [L]

    That above should work but it is not elegant and will create huge urls -- not to mention having to redo the links I already have :)

    Trying to build my site from the start with this involved ..
     
    trixs, Jul 16, 2007 IP
  4. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for reply!

    I dont know how to make the rewrite input the correct variable that way..
    For instance how would it know that there is only 2 categories and a row vs
    4 categories and a row...

    Maybe I just dont understand mod_rewrite fully which is probably true!
     
    trixs, Jul 16, 2007 IP
  5. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    What do you think of this answer?

    RewriteRule
    ^index/(.*)/(.*)/?row=(.*)$ index.php?cat1=$1&cat2=$2&row=$3 [L]

    would rewrite
    www.#.com/index/bleh/meh/?row=3

    toooo

    www.#.com/index.php?cat1=bleh$cat2=meh&row=3

    Wow, looks like it will work.. Going to try :)
     
    trixs, Jul 16, 2007 IP
  6. trixs

    trixs Peon

    Messages:
    111
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Webgeek -

    I didnt understand what you said at first - It ended up working :)

    Thanks
     
    trixs, Jul 16, 2007 IP