0

How to redirect subdomain locally on my computer without modifying the code?

Let's say, subdomain 'static.company.com' should be redirected to 'localhost/static'.

Edit

I forgot to mention that I had WAMP installed. WAMP already have 'alias directories' that do exactly what I needed - redirect URI to the folder on local server. There is a command-line interface where you should set URI (in my case, multimedia) and /path/to/the/folder/on/the/server/.

You can find this post http://www.itsananderson.com/2009/01/wamp-alias-directories/ useful also if your URI doesn't have slash(/) at the end.

1
  • /etc/hosts file plus a little Apache configuration.
    – ceejayoz
    Aug 1, 2012 at 12:47

1 Answer 1

0

You would either need an entry on your local DNS server or an entry in your machine's host file to point to itself.

As for Apache you could simply setup a mod_rewrite rule to transform the URL when it comes in.

http://httpd.apache.org/docs/2.2/rewrite/

7
  • I've added line "static.company.com 127.0.0.1" to hosts and restarted machine. When I go there (http://static.company.com) it is not redirected at all. Am I doing something wrong?
    – ruruskyi
    Aug 1, 2012 at 13:15
  • What does a DNS query of "static.company.com" return? It should return 127.0.0.1. You still have to make Apache changes that I mentioned to get Apache to serve the right resource. Aug 1, 2012 at 13:18
  • should be reversed like so: 127.0.0.1 static.company.com. Good! Now I am going to configure Apache..
    – ruruskyi
    Aug 1, 2012 at 13:29
  • Not sure this is correct: RewriteCond %{HTTP_HOST} ^static.company.com[nc] RewriteRule ^(.*)$ http://localhost/static.company.com/$1 [r=301,nc]
    – ruruskyi
    Aug 1, 2012 at 13:33
  • This two lines should be added to the server configuration (not to .htaccess) ProxyPass /multimedia http://localhost/static.company.com/multimedia ProxyPassReverse /multimedia http://localhost/static.company.com/multimedia
    – ruruskyi
    Aug 6, 2012 at 9:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.