问题
I want to "mask" a URL. I have a subdomain that I do not want people to know about on my website. So what I am needing help with is this:
My website is: www.example.com
I have a subdomain: sub.example.com/test.php
When someone clicks on a link that points to sub.example.com/test.php, I do not want "sub.example.com/test.php" to show in the url bar. I would like for www.example.com to show instead.
回答1:
When you want to link to sub.example.com/test.php, change the link to something else, like www.example.com/sub/test.php or something. Then in your .htaccess file in the document root for www.example.com add this:
RewriteEngine On
RewriteRule ^sub/(.*)$ http://sub.example.com/$1 [L,P]
This will internally proxy any request for www.example.com/sub/ to sub.example.com. So when someone requests http://www.example.com/sub/path/file.html, they really get http://sub.example.com/path/file.html except their URL address bar still has the example.com URL. You just need to make sure to change all of your links to sub.example.com to example.com/sub/
来源:https://stackoverflow.com/questions/8954987/how-to-mask-a-url-in-a-website