Author |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Mon 11 Jun '07 19:14 Post subject: Mapping domain names on localhost |
|
|
I am developing a site. For testing it locally, I installed Apache.
Now, I want to map my domain (say www.example.com) to the example folder in htdocs, so that my server-relative links work fine, and I dont have to modify them when I upload the files to the server.
Please tell me, how can I do that??? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Mon 11 Jun '07 21:56 Post subject: |
|
|
a) you can edit your host file in C:\WINDOWS\system32\drivers\etc
b) easier you can put your links relativ! without hostname. This is the most way web pages are programmed. |
|
Back to top |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Tue 12 Jun '07 12:44 Post subject: |
|
|
There ae site sub-domains for which I obviously will have to use the hostname & therefore perform a host mapping on the local host.
I have made an entry in the host file for my top-level domain. That's fine.
But, 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? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Tue 12 Jun '07 14:17 Post subject: |
|
|
You can also put the sub.domain into the host file and add name based vhosts to your httod.conf
Attention you also have to put your main (toplevel) domain into a vhost!
See the docs for more details
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
If you still have a question, you are welcome to ask again. |
|
Back to top |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Wed 13 Jun '07 10:13 Post subject: |
|
|
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 & stll 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)... |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Wed 13 Jun '07 11:16 Post subject: |
|
|
Here is an working example. Keep the * if you change it for your needs
Code: |
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdminyour@example.com
DocumentRoot C:/apache2/htdocs
ServerName example.com
ServerAlias www.example.com
ErrorLogC:/apache2/logs/error.log
CustomLog C:/apache2/logs/access.log common
<Directory " C:/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin ich@example.com
DocumentRoot C:/apache2/htdocs/ex
ServerName ex.example.com
ServerAlias www.ex.example.com
ErrorLogC:/apache2/logs/ex.error.log
CustomLog C:/apache2/logs/ex.access.log common
<Directory "C:/apache2/htdocs/ex">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
|
|
|
Back to top |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Wed 13 Jun '07 12:36 Post subject: |
|
|
Thank you very much. I was missing the <Directory> directive.
Its working fine, but for just one thing I mentioned before.
The server-relative links in pages in the ex directory (e.g. /Images) should continue to resolve with respect to the directory root, i.e. htdocs.
Can I achieve it too??? |
|
Back to top |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Fri 15 Jun '07 12:07 Post subject: |
|
|
My sub-domains are resolving correctly now using the VirtualHost directives.
There's one additional thing I want to accopolish now. My sub-domain ex.example.com resolves to htdocs/ex.
But using this configuration, server-relative links (relative to my top-level Directory Root i.e. /htdocs) in ex directory files (e.g. /Images/sample.jpg) do not resolve correctly, obvioulsy.
So, I thought why not rewrite ex.example.com to example.com/ex. I tried to use mod_rewrite directive for it, but my error logs showed me that I am coding the directive incorrectly.
So, can you provide me sample solutions for the following:
1) Rewrite ex.example.com to example.com/ex
2) Rewrite www.ex.example.com again to example.com/ex
3) Finally. rewrite any sub-domain to its corresponding directories, i.e.
sub-domain.example.com to example.com/sub-domain; and
www.sub-domain.example.com again to example.com/sub-domain.
And by the way, thanks in advance. |
|
Back to top |
|
tdonovan Moderator
Joined: 17 Dec 2005 Posts: 611 Location: Milford, MA, USA
|
Posted: Fri 15 Jun '07 16:19 Post subject: |
|
|
mod_rewrite is not necessary for this.
You could put Alias commands inside the <VirtualHost> blocks for each htdocs-based directory.
For example, on Windows: Code: | Alias /Images C:/xampp/htdocs/Images | or if you run Unix: Code: | Alias /Images /opt/lampp/htdocs/Images |
-tom- |
|
Back to top |
|
Rahul
Joined: 11 Jun 2007 Posts: 9
|
Posted: Sat 16 Jun '07 19:01 Post subject: |
|
|
Yes, Alias can also be used for the puspose. Thanx!!!
But, I am still not getting the expression for mod_rewrite correct. Can you provide the sample solutions??? |
|
Back to top |
|