Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts

    mod_rewrite help needed!

    Hi,

    I'm basically lost with mod_rewrite! I have a php page that pulls up entries to the db using GET and the id.

    So the web address is www.mysite.composts.php?id=1 (for example).

    What i want instead is www.mysite.com/title-of-post

    Could anyone please give me a hand?
    Thanks!

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Could anyone please give me a hand?
    You'd need to generate the "title-of-post" part for each post and save it in a separate column (and then apply some UNIQUE INDEX to it).

    That may not be an easy task when considering the chances of two posts with the same title and changing the "title-of-post" column along with any change in the original title of the post.

    The easy way is to make the urls like www.mysite.com/1_title-of-post or www.mysite.com/1-title-of-post and then extract the id from url to retrieve it from DB.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I'm the only one who can put content onto the site, so name clashes won't be a problem.

    I'm struggling with mod_rewrite at a more basic level though at the moment.

    I can't even turn www.mysite.com/posts.php?id=1 into www.mysite.com/1. (Or any other simple variation on that).

  • #4
    New Coder
    Join Date
    Aug 2011
    Posts
    20
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok, so I've changed my SQL querys so that it doesn't use ID's anymore. Instead it searches by a new field, 'url', which i set myself.

    So now i have:
    www.mysite.com/posts.php?url=whatever-i-chose

    But what i want is:
    www.mysite.com/whatever-i-chose

    Could anyone tell me how i can achieve this?

    Thanks!

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Could anyone tell me how i can achieve this?
    Have a look into http://www.google.com/search?q=apache+friendly+urls
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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