Results 1 to 3 of 3

Thread: friendly urls

  1. #1
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default friendly urls

    Hello,

    I've managed to make friendly urls, but there's a slight problem with it heres an example what i get:

    http://www.gamerspot.co.uk/news_area...20IV%20Delay!/

    but as you can see, it displays the news title with "%20" which makes the url look messy. And what i want it to look like:

    http://www.gamerspot.co.uk/news_area...GTA:IV-Delay!/

    And my .htaccess code looks like this:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule view_article/newsID/(.*)/title/(.*)/ view_article.html?newsID=$1&title=$2
    RewriteRule view_article/newsID/(.*)/title/(.*) view_article.html?newsID=$1&title=$2
    Is there a way that would get rid of "%20" and replace it with either "-" or "+" ?

    Ben

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Rather than using a full version of the title, it's easier for users to remember if you "slugify" it, removing unneccessary punctuation (which also tends to look ugly in URLs):
    Code:
    function slugify($str) {
      return strtolower(preg_replace(array('/ /', '/\W/'), array('/-/', ''), $str));
    }
    Also, IMO, your URLs are too long. You can remove the variable names for a start, as well as having view_article be a sensible default action for articles, and end up with an URL that looks like /news_area/article/1/ps3-caused-gta-iv-delay.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    where do i put that code ?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •