I have a site with many links that send a get request, how can I hide the variables. Eg, www.mysite.com/home.php?id=name to www.mysite.com/name and second link www.mysite.com/page.php?id=1 to www.mysite.com/1 I was able to achieve to hide the first link using htaccess, but the previous links, I couldn't. All issues address on this sites were based on single link. Thanks in advance!
- possible duplicate of PHP Rewrite RulesMachavity– Machavity ♦2014-11-08 15:44:46 +00:00Commented Nov 8, 2014 at 15:44
Add a comment |
1 Answer
To differentiate between those 2 issues I think you can catch all numbers first and then check \w+ character later.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On RewriteBase / # skip all files and redirectories from rewrite RewriteCond %{REQUEST_FILENAME} -d [OR] RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^ - [L] RewriteRule ^(\d+)/?$ page.php?id=$1 [L,QSA] RewriteRule ^([\w-]+)/?$ home.php?id=$1 [L,QSA] 4 Comments
Mande Kira
Thanks for coming to my rescue. I tried to add more variables to the links, say page.php?I'd=1&control=new how can I change the code. Thanks once again. Am very new in htaccess
anubhava
You can add:
RewriteRule ^(\d+)/(\w+)/??$ page.php?id=$1&control=$2 [L,QSA]Mande Kira
I have tried it but got a 404 error, that's objet not found
anubhava
See it is difficult to add support to new question from comments section. Better to create a new question with all the information so that I can suggest better answer.