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
hide id with mod_rewrite
Moderator: General Moderators
Re: hide id with mod_rewrite
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?
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: hide id with mod_rewrite
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
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.
I know that if you search by id is much faster than text.
- flying_circus
- Forum Regular
- Posts: 732
- Joined: Wed Mar 05, 2008 10:23 pm
- Location: Sunriver, OR
Re: hide id with mod_rewrite
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.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.
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
Why do you want to hide the ID? What do you gain?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.