Boxerman Posted October 22, 2012 Share Posted October 22, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269793-rewrite-title-from-database/ Share on other sites More sharing options...
kicken Posted October 22, 2012 Share Posted October 22, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269793-rewrite-title-from-database/#findComment-1387096 Share on other sites More sharing options...
Boxerman Posted October 23, 2012 Author Share Posted October 23, 2012 Super that makes sense, i will test this. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/269793-rewrite-title-from-database/#findComment-1387098 Share on other sites More sharing options...
JsyJack Posted November 6, 2012 Share Posted November 6, 2012 Is it possible to use the ID (?id=1) to look up the title and replace the "?id=1" with the title using a mysql query? Quote Link to comment https://forums.phpfreaks.com/topic/269793-rewrite-title-from-database/#findComment-1390606 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.