SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help creating friendly URL

    I was going to post this on my previous post on the subject but sitepoint displayed some message encouraging me to create a new thread so here it is

    Basically I am using mod rewrite to rewrite a URL such as

    http://www.mysite.com/viewDetails.php?id=5286

    so I can type in

    http://www.mysite.com/listings/friendlyURL

    and it goes to the above.

    I have added an extra field in my database for the friendlyURL

    Here is my code

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^listings/([0-9]+)/?$ viewDetails.php?friendlyURL=$1

    If I try the following:

    http://www.mysite.com/listings/the-gurnards-head

    I get the following error:

    Not Found

    The requested URL /listings/the-gurnards-head was not found on this server.

    Any assistance much appreciated.

    Thanks

    Paul
    Mediakitchen Limited
    App Development | Website Design & Development | Flash Game Development
    Somerset, UK
    http://www.mediakitchen.co.uk

  2. #2
    SitePoint Member
    Join Date
    Sep 2009
    Location
    UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul,

    The rewrite code you posted is wrong. Your using ([0-9]+) which means match any number of characters between 0-9, so a URL like this would work:

    yoursite.com/listings/1-2-3-4-5

    To do what you want with the example URL provided you need to use the [a-z] characters and you also need to add something to account for the hypen.

    Lastly, your URL should end with a slash like so, otherwise you need to remove the last slash from the rewrite just before the question mark.

    yoursite.com/listings/the-gurnards-head/

    Give this one a try:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^listings/([-a-z]+)/?$ viewDetails.php?friendlyURL=$1
    HTH

  3. #3
    SitePoint Guru
    Join Date
    Aug 2004
    Location
    Taunton, UK
    Posts
    787
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Andy - that works a treat with both slash at the end and without the slash

    Thank you very much indeed!

    Cheers

    Paul
    Mediakitchen Limited
    App Development | Website Design & Development | Flash Game Development
    Somerset, UK
    http://www.mediakitchen.co.uk


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
  •