Mapping domain names to localhost

I am developing a site. For testing it locally, I installed Apache.
I have mapped my domain name (say www.example.com) in the C:WINDOWSsystem32driversetc directory to 127.0.0.1, so that I can perform testing locally.

There are site sub-domains for which I obviously will have to use the hostname & therefore perform a host mapping on the local host. Now I want to map the sub-domains to sub-directories of the root localhost folder (like we do for A or CNAME records).

Can I do that, becuase with this appraoch I can test my site completely locally, and then upload it without any changes to the link destinations?

Comments

  • : I am developing a site. For testing it locally, I installed Apache.
    : I have mapped my domain name (say www.example.com) in the
    : C:WINDOWSsystem32driversetc directory to 127.0.0.1, so that I
    : can perform testing locally.
    :
    : There are site sub-domains for which I obviously will have to use
    : the hostname & therefore perform a host mapping on the local host.
    : Now I want to map the sub-domains to sub-directories of the root
    : localhost folder (like we do for A or CNAME records).
    :
    : Can I do that, becuase with this appraoch I can test my site
    : completely locally, and then upload it without any changes to the
    : link destinations?

    This might be an answer: http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#uservhosts
    The example there uses userdirs, but could perhaps be used to map your subdomains to folders, which are located on your main domain.
  • Its still not working for me.
    So, let me be very specific. What I am trying to achieve is using all kind of links in my web-pages & still be able to test my site completely locally.

    Suppose my top-level domain is example.com. I also have a sub-domain ex.example.com.

    Now, in my hosts file in the etc directory, I have mapped both the domain & the sub-domain to 127.0.0.1.

    So, both of them resolve to my directory root, htdocs.
    I want htdcos to remain the root-directory for my domain, & I want to resolve ex.example.com to htdocs/ex.
    Obviously, the server-relative links in pages in the ex directory should continue to resolve with respect to the directory root, i.e. htdocs.

    So, is there any way to achieve this. Please be very specific about the configuration entries I have to make, & in which files to make them (i.e. http, or .htaccess etc. or whichever)...
  • : Its still not working for me.
    : So, let me be very specific. What I am trying to achieve is using
    : all kind of links in my web-pages & still be able to test my site
    : completely locally.
    :
    : Suppose my top-level domain is example.com. I also have a sub-domain
    : ex.example.com.
    :
    : Now, in my hosts file in the etc directory, I have mapped both the
    : domain & the sub-domain to 127.0.0.1.
    :
    : So, both of them resolve to my directory root, htdocs.
    : I want htdcos to remain the root-directory for my domain, & I want
    : to resolve ex.example.com to htdocs/ex.
    : Obviously, the server-relative links in pages in the ex directory
    : should continue to resolve with respect to the directory root, i.e.
    : htdocs.
    :
    : So, is there any way to achieve this. Please be very specific about
    : the configuration entries I have to make, & in which files to make
    : them (i.e. http, or .htaccess etc. or whichever)...

    In your httpd.conf file, you need to check if the mod_rewrite is loeaded (in the LoadModule list). Add these lines (untested) to the same file:
    [code]
    RewriteEngine on
    RewriteCond %{HTTP_HOST} [^.]+.example.com$
    RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
    RewriteRule ([^.]+).example.com(.*) /htdocs/$1$2
    [/code]
    For more info see the Rewrite module documentation for more info.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories