How to bring url's like database.php?cid=1 to /this-is-title.php ?

Discussion in 'Apache' started by poseidon, Jan 6, 2007.

  1. #1
    hi, I have urls like http://www.<mysite>.com/browse.php?cid=1 and I want to make them seo friendly with relevant names like http://www.<mysite>.com/this-is-title.php where "This is Title" is the title of the page ? how can I do this ?
     
    poseidon, Jan 6, 2007 IP
  2. oziman

    oziman Active Member

    Messages:
    199
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #2
    You need to have access to your .htaccess and knowledge of mod-rewrite.
     
    oziman, Jan 6, 2007 IP
  3. poseidon

    poseidon Banned

    Messages:
    4,356
    Likes Received:
    246
    Best Answers:
    0
    Trophy Points:
    0
    #3
    yes I do have access to .htaccess :) but don't have enough kowledge of mod-rewrite rules. I tried some codes by reading nintendo's FAQ but the code didn't seemed to be working.
     
    poseidon, Jan 6, 2007 IP
  4. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #4
    What have you got so far?

    It'll save a lot of hassle if you include the ID in your new 'friendly' url as well though.

    /235-this-page-title.php to /browse.php?cid=235
    RewriteRule ^([0-9]+)-(.*)\.php browse.php?cid=$1 [L,QSA]
    Code (markup):
    ^ means must start with
    [0-9] matches any number
    + means we want 1 or more number
    Put that in brackets so it's accessible for our rewrite destination.

    Then we have (.*) - the period indicates any character and the * means 0 or more times. Add the .php extension, escaping the period special properties with a backslash.

    Put that all together in our desired format to get:
    ([0-9]+)-(.*)\.php

    That means we're matching:
    452-pie.php
    423932-.php
    3-chickens-can-fly.php
    but not
    404.php (no dash)
    article953-pie.php (doesn't start with a number)

    The rewrite destination is fairly self-explanatory.

    Then we add the L flag so mod_rewrite knows not to apply any more rules. And the QSA for Query String Append: 34-title.php?show=printable would become browse.php?cid=34&show=printable.

    Hope that helps..
     
    rodney88, Jan 6, 2007 IP
    LaCabra and poseidon like this.
  5. nialler

    nialler Peon

    Messages:
    97
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thats a really handy explanation rodney88, useful for me too
     
    nialler, Jan 8, 2007 IP