将地址栏中的URL从子域更改为主域
我有一个网站,其前端使用HTML5 + javascript + jquery编码,后端使用PHP.
I have a website with front end coded in HTML5 + javascript + jquery and backend in PHP.
我有一个域
example.com
和一个子域
a.example.com
在浏览器上,我将example.com重定向到a.example.com.现在,我希望即使向用户显示a.example.com,地址栏也应将example.com显示为已打开的域.
On the browser i redirect example.com to a.example.com. Now i want that even if a.example.com is shown to the user, the address bar should show example.com as the domain which is opened.
我该怎么做?如果真实网址属于同一主域名,是否可以欺骗用户并向用户显示另一个网址?
How do i do this? Is there a way to spoof the real url and show another url to the user if they belong to the same main domain name?
谢谢
除了使用浏览器重定向外,您还可以使用服务器在浏览器中显示example.com,同时实际呈现a.example.com
Instead of using browser redirects you can use your server to show example.com in browser while actually rendering a.example.com
这可以在Virtualhost设置下的apache服务器(如果使用PHP + APACHE)中使用
This can be done using in apache server(if you are using PHP + APACHE ) under Virtualhost setting
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
ProxyPassMatch ^/(*)$ http://a.example.com/$1
...
...
</VirtualHost>
这将成为从example.com到a.example.com的所有请求的代理,而无需更改url.它将在a.example.com下运行您的代码.
This will make a proxy for all requests from example.com to a.example.com without changing url. It will run your code under a.example.com.
注意:这需要Apache中的mod_proxy模块
Note: This requires mod_proxy module in apache
希望这会有所帮助!