tsuby Posted June 28, 2013 Share Posted June 28, 2013 Hey guys! I have a little problem with link rewriting.For example, when I go to the page /articles/that-article-is-nice, I got the server to use /view.php?article_name=that-article-is-nice. My question is, how can I use that slug name(which was transformed previously) to get the wanted article from the database? Because in the database I would have something like 'That article is... nice.?', whereas my article_name variable is different: 'that-article-is-nice'.Can you give me any ideas on how I should approach this? My worst problem is SQL, I'm really not familiarised with it. Quote Link to comment https://forums.phpfreaks.com/topic/279657-need-an-idea/ Share on other sites More sharing options...
Solution Zane Posted June 28, 2013 Solution Share Posted June 28, 2013 (edited) put the article id number within the rewrite as well. In other words, RewriteRule /articles/(.*)_article_name /view.php?article_id=$1 [L] The rule of thumb is that unless you are searching for rows that are similar and alike, never search using a string. The purpose of indices is to keep an index. If you know the index number there is not point in searching by the name of the article. It would be like searching through a literal library for a book by its name and not its ISBN. Edited June 28, 2013 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/279657-need-an-idea/#findComment-1438376 Share on other sites More sharing options...
tsuby Posted June 28, 2013 Author Share Posted June 28, 2013 Thank you for your answer, I appreciate it. That is what I had in mind, also, but it didn't really seem elegant to me. Now that I look more closely on some websites that I wanted to take an example from, they really use this; and so I will not have any problem implementing it in my website. Again, thanks a lot for your answer! Quote Link to comment https://forums.phpfreaks.com/topic/279657-need-an-idea/#findComment-1438402 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.