Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Mapping domain names to localhost

r_honeyr_honey Posts: 11Member
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

  • zibadianzibadian Posts: 6,349Member
    : 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.
  • r_honeyr_honey Posts: 11Member
    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)...
  • zibadianzibadian Posts: 6,349Member
    : 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.