dakasadaka Posted February 18, 2010 Share Posted February 18, 2010 Hello there, I'm trying to make my urls to have the post title in the url. Now I have index.php?id=2 and I want to have title-of-post.html I know that I need to use .httacces and rewrite on, but when I ask in my database id, can I just ask for title of post and then put it after id=post-of-title.html Or are they smarter and faster ways to make this? thnx, Davor Radic Quote Link to comment https://forums.phpfreaks.com/topic/192489-mod-rewrite-and-seo-friendly-urls/ Share on other sites More sharing options...
cags Posted February 18, 2010 Share Posted February 18, 2010 Since the title of an article/page is often not forced to be unique generally speaking URLs will include both. For example... mysite.com/article/10/my-article.html You can then use a rule something like this... RewriteRule ^article/([0-9]+)/[a-zA-Z0-9-]+\.html /article/index.php?id=$1 You system will essentially check that the title matches against the characters you allow, but ultimately ignores it since it is the id that is important. If your title is a true 'permalink' that is unique for that article you can simply change that to something like... RewriteRule ^article/([a-zA-Z0-9-]+)\.html /article/index.php?title=$1 ...and use the title in a similar manner to what your currently using the id. Quote Link to comment https://forums.phpfreaks.com/topic/192489-mod-rewrite-and-seo-friendly-urls/#findComment-1014252 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.