Jump to content

Need an idea


tsuby
Go to solution Solved by Zane,

Recommended Posts

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.

Link to comment
Share on other sites

  • Solution

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 by Zane
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.