Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-24-2012, 05:42 PM   PM User | #1
Cobb
New Coder

 
Join Date: Aug 2011
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
Cobb is an unknown quantity at this point
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!
Cobb is offline   Reply With Quote
Old 02-25-2012, 09:21 AM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 02-25-2012, 09:46 AM   PM User | #3
Cobb
New Coder

 
Join Date: Aug 2011
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
Cobb is an unknown quantity at this point
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).
Cobb is offline   Reply With Quote
Old 02-25-2012, 08:24 PM   PM User | #4
Cobb
New Coder

 
Join Date: Aug 2011
Posts: 20
Thanks: 3
Thanked 0 Times in 0 Posts
Cobb is an unknown quantity at this point
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!
Cobb is offline   Reply With Quote
Old 03-03-2012, 12:08 PM   PM User | #5
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Could anyone tell me how i can achieve this?
Have a look into http://www.google.com/search?q=apache+friendly+urls
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 PM.


Advertisement
Log in to turn off these ads.