2

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!

1

1 Answer 1

2

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] 
Sign up to request clarification or add additional context in comments.

4 Comments

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
You can add: RewriteRule ^(\d+)/(\w+)/??$ page.php?id=$1&control=$2 [L,QSA]
I have tried it but got a 404 error, that's objet not found
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.