Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthormihai
    • CommentTimeDec 11th 2006
     permalink
       i've just started playing with this mod_rewrite and am jsut trying to find A GOOD LIST of examples.
       i mean... all i am trying to do is get
    mysite.com/band/blink182 to redirect to mysite.com/band.php?q=blur
       but it seems so hard for me to understand.
       so can anyone please help me... at least post 2-3 examples for me to experiment with.

    Mike
    • CommentAuthorvarland
    • CommentTimeDec 11th 2006
     permalink

    This may not be enough for you, but try something like this:

    RewriteEngine On
    RewriteRule ^band/([a-zA-Z0-9_]+)/?$ /band.php?q=$1

    Here's what it says:

    • The URL starts with "band/". The "^" means starts with.
    • After "band/", the URL contains one or more (given by the plus sign after the closing bracket) of the following characters: a - z, A - Z, 0 - 9, or underscore (given by "[a-zA-Z0-9_]"). This is the band name.
    • The URL may or may not have a trailing slash (given by "/?"). The "$" means ends with.

    Then, you're telling it to redirect to band.php and pass it the band name as the querystring. mod_rewrite will save anything you enclose in parentheses as a variable. The first "()" contain the variable named $1, the second contain $2, and so on. Therefore, "[a-zA-Z0-9_]+" in the rule given above will store the band name in $1. If you want to test it, add "[R]" to the end of the rule. This will actually redirect the user to "/band.php?q=whatever" instead of leaving the URL as "/band/whatever".

    Sorry if this isn't as comprehensive as you want, but hopefully it'll get you started.

    • CommentAuthormihai
    • CommentTimeDec 11th 2006
     permalink
    great example... i mean, all the inportant stuff in a few rows, 10x
Add your comments
    Username Password
  • Format comments as (Help)