title to url conversion

Discussion in 'PHP' started by subzero27, Jun 26, 2007.

  1. #1
    Hello,
    I have a site where in the url's are in this format http://www.domain.com/category.php?id=30987

    i want to change it to http://www.domain.com/page-title.php

    Can someone please help me out on this as like what code i need to attach to get the title to be parsed and displayed in the url after the domain name and title words be separated by " - " symbols. Do i have to make some mods in the .htacesses file too ?

    Thanks for your help.
     
    subzero27, Jun 26, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You will have to change your category.php file, so that it gets the category based on a unique name, instead of an ID. I can't help you with that without seeing your code.

    As for the htaccess file, it'd be something like this:
    
    RewriteEngine On
    RewriteRule ^(.*)\.php$ category.php?title=$1
    
    Code (markup):
     
    nico_swd, Jun 26, 2007 IP
  3. subzero27

    subzero27 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Nico,
    Actually this is the exact req -


    Instead of : http://muzica dot x6 dot ro/melodia dot php?id=3442

    (please replace the dot word with " . " )

    The url should be:

    http://muzica dot x6 dot ro/strength-of-a-woman-3442.html

    Here are the two main files catagoria.php and melodia.php,please check the attachment.

    Thanks for your time,i really appreciate your help.
     

    Attached Files:

    subzero27, Jun 26, 2007 IP
  4. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    If you just want to turn http://muzica dot x6 dot ro/melodia dot php?id=3442
    into http://muzica dot x6 dot ro/strength-of-a-woman-3442.html You basically want to drop out all the spaces and non-alphanumeric characters from the title and put - in place of the spaces (search engines read that as a space), and then -<id of content>.html, and then add a rewrite rule like:
    RewriteRule ^(.*)-([0-9]+).html$ category.php?id=$2
    That reads <anything>-<##>.html, and passes the ## as the variable $_GET['id'] to category.php, so it keeps everything you currently have, and you just replace your links and add that line in your htaccess and you're set.
     
    projectshifter, Jun 26, 2007 IP
  5. subzero27

    subzero27 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    here is the .htaccess file that i have made after your suggestion


    RewriteEngine On
    RewriteRule ^(.*)-([0-9]+).html$ category.php?id=$2

    php_flag register_globals on
    <Files 403.shtml>
    order allow,deny
    allow from all
    </Files>

    is this okay.....or i need to attach some other code somewhere because it doesn't seem to be working.
     
    subzero27, Jun 26, 2007 IP
  6. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    For the record (don't remove it because apparently your code needs it), but register_globals on is a bad idea, it's disabled by default in php for a reason. But anyway, what you have is right. It's not going to automatically change your links, but doing blah-blah-friggity-blah-30987.html should display category.php?id=30987
     
    projectshifter, Jun 26, 2007 IP
  7. subzero27

    subzero27 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks for the help,But somehow its not working :(

    Is there any way in which i can get the title shown in the url....i have the end user as well in my mind not just for the search engines sake.
     
    subzero27, Jun 26, 2007 IP
  8. projectshifter

    projectshifter Peon

    Messages:
    394
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #8
    You change your urls that are being displayed to include the title-id.html, it's really a simple concept.
     
    projectshifter, Jun 26, 2007 IP
  9. subzero27

    subzero27 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thanks projectshifter but i am really a dumbass when it comes to php.Can you tell me how do i implement it.
     
    subzero27, Jun 27, 2007 IP
  10. subzero27

    subzero27 Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Any inputs guys ???
     
    subzero27, Jun 27, 2007 IP