Jump to content

Recommended Posts

Evening all,

 

Your mission if you choose to accept is...

 

My problem is, at the current moment i have the following url: movie.php?id=1

 

where i would like to rewrite to

 

/watch/title-of-movie-here

 

How would i go about this? what do i need to do?

 

Many thanks all.

Link to comment
https://forums.phpfreaks.com/topic/269793-rewrite-title-from-database/
Share on other sites

You would create a rewire rule that passes the title of the movie to a script, then you use that title to lookup the movie. Eg:

 

RewriteRule /watch/(.*)$ movie.php?title=$1

 

Then in movie.php you would use $_GET['title'] to query the database for the movie and display it.

 

You'll need to make sure all your titles are unique for each movie in order to find the proper one.

 

An alternative would be to do like the forums here do and stick the ID and the title in the URL. Eg:

/watch/1234-my-movie

 

Then you would not need to have a unique title because you can look them up by the ID, but you still get a nicer looking URL. A rule like this should handle that type of setup:

RewriteRule /watch/(\d+)-.*$ movie.php?id=$1

 

 

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.