Redirect subdomain to webapp

  • Posted January 31, 2014

I would like to redirect a subdomain to an URL of a webapp. Something like: >>>>

How can I do it?


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.


To do so, you have 2 solutions :

  • If you want your users to see the URL as another.domain:8080/myWebApp explicity, you can use a simple PHP redirect placing a index.php file in the docroot ofr containing the following:
header('Location: ');

This solution is not the smartiest one, as it shows an unusual port in the URL for your webapp.

  • The second solution could be using Apache or Nginx as a reverse proxy for your webapp. With nginx configuration file, this would be a configuration of that kind, to set on the server hosting :
location / {
    proxy_cache cache;
    proxy_cache_valid 12h;
    expires 12h;
    proxy_cache_use_stale error timeout invalid_header updating;

I would rather opt for the 2nd solution, as the reverse proxy will conserve in the URL for your web users.

Hope this could help,


– rustx

Do you want this to be permanent or temporary? There are various ways to do this. You could create an index file in the document root that redirects, setup rewriting of a location in the virtual host depending on what web server you use, etc.