How to mask a URL in a website?

纵饮孤独 提交于 2020-01-15 08:05:23

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!