0

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

charak
  • 187
  • 3
  • 15

3 Answers3

3

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.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • I have used window.history.pushState to show another url of the same website to the user. I was wondering if same is possible with subdomains of the same domain. – charak Feb 22 '17 at 07:37
  • The same isn't possible, no. – Cerbrus Feb 22 '17 at 07:41
2

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 !!

Mayank
  • 727
  • 6
  • 9
0

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

landrykapela
  • 442
  • 6
  • 15