MarcyS Posted October 30, 2013 Share Posted October 30, 2013 I've been trying for hours to rewrite my current url: domain.com/post.php?id=7 ...and make it appear like this: domain.com/this-is-my-title I haven't been able to do it yet. All the online examples show using an id first or something, but I really like just .com/title only. So.. can I do that? I've seen other sites achieve it, such as upworthy, so I know it's possible. Part II: How would I call the new page from index.php? I have a database table called 'article' and the column I need is 'title' and there's obviously a postid for each entry.. I can manage to use php enough to put a dash in between all the words of the title and remove all special characters but... Not sure how to make the call though. I mean... I see that $theArticle['title'] returns the title in my current code, but displaying the url only? Is what I'm trying possible? Thanks for any suggestions! Quote Link to comment https://forums.phpfreaks.com/topic/283426-trying-to-rewrite-for-domaincomtitle/ Share on other sites More sharing options...
Solution requinix Posted October 30, 2013 Solution Share Posted October 30, 2013 You can't do that directly. Rewriting works by taking pieces of the URL and rearranging them into something you can use with your PHP script. That means all you have to work with (in your example) is "this-is-my-title". You can't conjure up the id=7 from that. However your PHP script can. If you must use "/this-is-my-title" then the simplest course of action is to modify your post.php so that it can take a title as well as/instead of an ID number. /post.php?title=this-is-my-title Quote Link to comment https://forums.phpfreaks.com/topic/283426-trying-to-rewrite-for-domaincomtitle/#findComment-1456158 Share on other sites More sharing options...
MarcyS Posted October 30, 2013 Author Share Posted October 30, 2013 Well at least I won't beat my head against the wall over this anymore. Thanks for letting me know that it can't really be done this way. I modified htaccess to allow for post/id/title.. and that's much better than what it was. Thanks for the reply! Quote Link to comment https://forums.phpfreaks.com/topic/283426-trying-to-rewrite-for-domaincomtitle/#findComment-1456219 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.