问题
I have a website with front end coded in HTML5 + javascript + jquery and backend in PHP.
I have a domain
example.com
and a subdomain
a.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?
Thanks
回答1:
Instead of using browser redirects you can use your server to show example.com in browser while actually rendering a.example.com
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>
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.
Note: This requires mod_proxy module in apache
Hope this helps !!
回答2:
For security reasons, this isn't possible.
You have no control over what url the browser shows the user, other than having the user navigate to a specific url.
Imagine, if this were possible, how many malicious websites would pretend to be a site they're not.
回答3:
If the aim is spoofing the address in the browser that is not a good idea. But if you want to show content of a.example.com while maintaining the address of example.com then you can go with the php include ('http://a.example.com')
in your example.com
index file. You should however enable url include in your php.ini
file.
The other way is to use the <iframe src='http://a.example.com'></iframe>
in your example.com
index file so that the user always sees the example.com
address while content is from a.example.com
来源:https://stackoverflow.com/questions/42385243/change-url-in-address-bar-from-subdomain-to-main-domain