BandonRandon Posted December 17, 2008 Share Posted December 17, 2008 Hello, this is my first attempt at writing my own clean URLs using mod_rewrite. what i currently have is a link like http://bandonrandon.com/news/?action=view&id=61 and i have figured out how to rewrite this as bandonrandon.com/news/view/61 by using RewriteRule ^news/view/(.+)/?$ news/index.php?action=view&id=$1 [L] however i would like to also have bandonrandon.com/news/61 do the same thing. i tried RewriteRule ^news/(.+)/?$ news/?action=view&id=$1 [L] that didn't work. I would ideally like to make the URL something like news/title_of_article but don't know how to pull the title out of the database and into the URL also i read something about adding a "Hash" to the database so the hash would be "title_of_post" instead of title of post. Is this the correct way to do this. Any Help would be great! Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted January 1, 2009 Share Posted January 1, 2009 if you use the first code the RewriteRule ^news/view/(.+)/?$ news/index.php?action=view&id=$1 [L] Just change the second part of it to this RewriteRule ^news/view/(.+)/?$ news/index.php?action=view&title=$1 [L] And get your PHP script to match up the titles. Hope i helped Quote Link to comment Share on other sites More sharing options...
BandonRandon Posted January 11, 2009 Author Share Posted January 11, 2009 Thanks Paul, I could do that however the problem would be that I believe that the titles would have to be in URL format ie something "site.com/firstword%20secondword%20%thirdword" i could fix this two ways one by adding a string replace doing something like replace" %20" with "-" or (this is probably what I'll do) add a permalink field to the database what contains what the url should be. Another issue i see with with this is that the if i had 2 post with the same title this could cause an error and do weird crap. the "id" is auto increment meaning that there will never be 2 post with the same id. thanks for your idea that was a good start to helping me understand clean urls. This is for a personal project so I'm not too worried about the time-line. Quote Link to comment 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.