Question

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

Was it helpful?

Solution

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]

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top