Page 1 of 1

hide id with mod_rewrite

Posted: Wed Nov 02, 2011 7:29 am
by dotphp
Hi.

I have a link like this:
index.php?page=article-title&id=12

article-title and id are dynamical

How can I show in my address bar only: http://www.website.com/article-title/
not http://www.website.com/article-title/12/

What I must change in htaccess for this.

Thanks

Re: hide id with mod_rewrite

Posted: Wed Nov 02, 2011 7:33 am
by Jade
I'm not an expert in mod_rewrite but I don't think you can. How else would you know which article to load unless you're storing it in a session? Also, if someone was to share the link with a friend how would the page know which ID to pull?

Re: hide id with mod_rewrite

Posted: Wed Nov 02, 2011 10:17 am
by flying_circus
dotphp wrote:Hi.

I have a link like this:
index.php?page=article-title&id=12

article-title and id are dynamical

How can I show in my address bar only: http://www.website.com/article-title/
not http://www.website.com/article-title/12/

What I must change in htaccess for this.

Thanks

This is not a problem to be solved with .htaccess, it's better handled by your request router.

If you know that all of your articles have a unique title, the simply pull the data from the database by querying the title, not the id.

Re: hide id with mod_rewrite

Posted: Thu Nov 03, 2011 3:28 am
by dotphp
If I fetch in databases using 'article-title' instead the id it will take longer to search for it ?
I know that if you search by id is much faster than text.

Re: hide id with mod_rewrite

Posted: Fri Nov 04, 2011 2:28 am
by flying_circus
dotphp wrote:If I fetch in databases using 'article-title' instead the id it will take longer to search for it ?
I know that if you search by id is much faster than text.
Best practice is to always create an index on commonly searched rows. If you are storing your article-title in a blob or text field, then it will likely take longer, but if it is stored in a reasonably sized varchar field, the performance difference would likely go undetected, that is, unless you have millions of article-titles.

I'm not a SQL expert by any means, I know enough to be dangerous. Maybe someone who has more experience in this field will chime in, but my suggestion is to index the search field.

Re: hide id with mod_rewrite

Posted: Fri Nov 04, 2011 10:49 am
by pickle
Why do you want to hide the ID? What do you gain?