views:

132

answers:

2

i have made a website in php.

There is a list of stories title stored in database and when user click any title among them then user is redirected to a page with a query string on it. like story.php?id=25

This means story with id 25 is now going to be displayed. Now i want to rewrite URL but when i rewrite it there occurs a problem.

In story.php page i am reading the query string like $_GET['id'].. but after URL rewriting i am unable to read it like this. Can any body suggests what to do

+2  A: 

You could use .htaccess to rewrite the long URLs server side, but not redirect the browser(so it still shows the long URL in the address bar), something like:

 RewriteEngine on
 RewriteRule story\/(\d+)\/(.+) story.php?id=$1

Just make you're long links look like www.site.com/story/25/This_is_the_title

scragar
You don’t need to escape the backslashes.
Gumbo
A: 

If you made some adjustments to your url string you could do this.

http://www.domain.com/story.php?story=25&title=some_name

Which after re-write could be this.

http://www.domain.com/25/some_name.html

Code:

RewriteEngine On
RewriteRule ^story/([^/]*)/([^/]*)\.html$ /story.php?story=$1&title=$2 [L]
Lee