raduenea Posted November 2, 2011 Share Posted November 2, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/ Share on other sites More sharing options...
geudrik Posted November 2, 2011 Share Posted November 2, 2011 If you use mod-rewrite to hide the ID, it is no longer a variable - eg: you can't GET it from the URL without having it in the URL... instead, you should use a form and POST the id to the article display page. Or just sanitize your GET variables... Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/#findComment-1284394 Share on other sites More sharing options...
cags Posted November 2, 2011 Share Posted November 2, 2011 This can't be done purely via .htaccess, it's not magic, if the value isn't in the URL, then you can't use it in the script. You would need to update your script to fetch information from the database using 'article-title' instead of using the id (12). Basically you change the title to be the identifier of the article. Thus obviously it would need to be unique. Given the URL you describe it would seem you are already using mod_rewrite rules, these would just need a bit of tweaking to not match the id. Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/#findComment-1284405 Share on other sites More sharing options...
raduenea Posted November 3, 2011 Author Share Posted November 3, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/#findComment-1284530 Share on other sites More sharing options...
cags Posted November 3, 2011 Share Posted November 3, 2011 Sure searching by id is probably quicker, but it's a matter of degrees. If you set the slug field to be an index, is that speed different actually going to be noticeable in a real-world environment?! Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/#findComment-1284547 Share on other sites More sharing options...
raduenea Posted November 3, 2011 Author Share Posted November 3, 2011 Obviously, if I search by id or title in 5000 rows, the speed will be the same. I think the speed difference if the search it's made in over 10000 rows. Quote Link to comment https://forums.phpfreaks.com/topic/250288-hide-id-with-mod_rewrite/#findComment-1284550 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.