How to write the SEO friendly url

Discussion in 'PHP' started by taham, Aug 19, 2010.

  1. #1
    Hi to all,

    In my sites, I have a article section separately. The url for the article section and each and every articles url is not SEO friendly. So, any one please let me know how to write the SEO friendly URL's?

    For your reference here is the URL structure: http://www.domain.com/Articles/viewArticle.php?id=37

    I want to rewrite the above URL as a SEO friendly with the corresponding article title. Please help me.

    Thanks in Advance,
     
    taham, Aug 19, 2010 IP
  2. Johnta

    Johnta Peon

    Messages:
    101
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you are using any kind of CMS like Joomla or Wordpress then , there is a plugin for that , if not you have to use mod_rewrite with htaccess file
     
    Johnta, Aug 20, 2010 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    What you want is written in your php files,
    and then you write a few lines in a .htaccess file, possible something like this, which at the moment should out-put http://www.domain.com/viewArticle_37.htm without editing any files.

    
    Options +FollowSymLinks
    
    RewriteEngine on
    
    RewriteBase /
    
    RewriteRule ^viewArticle_([^/]+)\.htm?$ Articles/viewArticle.php?id=$1 [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ Articles/viewArticle.php?id=([^&]+)\ HTTP/
    
    RewriteRule ^index\.php$ viewArticle_%1\.htm? [R=301,L]
    
    PHP:
    As above you need to edit the corresponding php file so instead of id number it shows the title of the article, when you do that edit the htaccess above.
     
    MyVodaFone, Aug 20, 2010 IP