View previous topic :: View next topic |
Author |
Message |
iarkin n00b
Joined: 04 Apr 2003 Posts: 18 Location: Left at Sirius, second star to the right
|
Posted: Sun Sep 14, 2003 5:10 pm Post subject: Apache2: how to redirect/alias www.domain.com to domain.com? |
|
|
Hello folks,
I've recently installed apache2, and i have set it to host kihlberg.org, which works fine. Now i really would like people going to www.kihlberg.org ending up on kihlberg.org. Either via a redirect och having www.kihlberg.org as an alias for kihlberg.org.
I have the A dns records för www. and the root domain pointing to the same ip.
After searching the web and reading a few faqs i came up with this little code snippet.
Code: | vhosts.conf
################# Alias för kihlberg.org
<VirtualHost kihlberg.org www.kihlberg.org>
ServerAdmin webmaster@kihlberg.org
DocumentRoot /home/httpd/htdocs/kihlberg.org/data
ServerName kihlberg.org
TransferLog /home/httpd/htdocs/kihlberg.org/logs/access.log
#ErrorLog /var/log/httpd-error.log
</VirtualHost> |
Now this doesn't really work as (i) expected.
Any ideas, pointers on what i could have done wrong here?
Cheers,
/iarkin |
|
Back to top |
|
|
Sanity1971 n00b
Joined: 13 Sep 2003 Posts: 19 Location: Holland
|
Posted: Sun Sep 14, 2003 8:24 pm Post subject: I do it the other way around usually |
|
|
For a client who use *.site.com where the * part is used to control the web application I have done pretty much what you want except in reverse.
I want mysite.com to go to www.mysite.com, I am sure you can figure out what you need to change.
At the top is this in my Vhost file.
Then the following for each virtual server.
Code: | # MYSITE.COM
<VirtualHost *>
ServerName mysite.com
RedirectPermanent / http://www.mysite.com
</VirtualHost>
<VirtualHost *>
ServerName www.mysite.com
ServerAlias *.mysite.com
DocumentRoot /path/mysite.com
</VirtualHost>
|
Serveralias allows anything to be prefixed to the domain name and it will endup at the same place.
I think this may work for you.
Code: | # MYSITE.COM
<VirtualHost *>
ServerName www.mysite.com
ServerAlias *.mysite.com
RedirectPermanent / http://mysite.com
</VirtualHost>
<VirtualHost *>
ServerName mysite.com
DocumentRoot /path/mysite.com
</VirtualHost>
|
|
|
Back to top |
|
|
iarkin n00b
Joined: 04 Apr 2003 Posts: 18 Location: Left at Sirius, second star to the right
|
Posted: Sun Sep 14, 2003 9:37 pm Post subject: |
|
|
Thank you very much for your quick answer!
This is what i ended up with:
Code: | NameVirtualHost 212.31.164.150
# kihlberg.org
<VirtualHost 212.31.164.150>
ServerName www.kihlberg.org
ServerAlias *.kihlberg.org
RedirectPermanent / http://kihlberg.org
</VirtualHost>
<VirtualHost 212.31.164.150>
ServerName kihlberg.org
DocumentRoot /home/httpd/htdocs
</VirtualHost>
|
Now here is why:
First i tried to copy and paste the code you gave me, and exchanged mysite.com for kihlberg.org. But alas, when i restarted apache, it spew out an error.
Code: | root@pyrrhon conf # /etc/init.d/apache2 start
* Starting apache2...
[Sun Sep 14 23:20:00 2003] [error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results [ ok ]
|
So, i exchanged the stars for my domain name. New error, got a "maximum redirection limit reached" when i pointed my browser to kihlberg.org.
Aight, changed from the domain name to my servers IP. Well now i can go to kihlberg.org and start apache but www.kihlberg.org still gives me "www.kihlberg.org could not be found, please check the name and try again".
So, i'm back a square one again. Is there maybe anything I fscked up when i rewrote the vhosts.conf?
Here is also a snippet from my apache2.conf, maybe it could be useful, dunno myself though.
Code: | ServerRoot /etc/apache2
ServerName kihlberg.org
LockFile /etc/apache2/apache2.lock
PidFile /var/run/apache2.pid
ErrorLog logs/error_log
LogLevel warn
DocumentRoot /home/httpd/htdocs |
Also one important thing that i failed to mention in my original post is that i use apache 2.0.47.
/iarkin |
|
Back to top |
|
|
devon l33t
Joined: 23 Jun 2003 Posts: 943
|
Posted: Mon Sep 15, 2003 12:39 am Post subject: |
|
|
I can't get www.kihlberg.org to resolve.
|
|
Back to top |
|
|
iarkin n00b
Joined: 04 Apr 2003 Posts: 18 Location: Left at Sirius, second star to the right
|
Posted: Mon Sep 15, 2003 12:48 am Post subject: |
|
|
oh...
*checks DNS config*
But it's it supposed to have propagated now, i changed it more than 48h ago.
Oh well, guess i'll just have to wait then.
Thanks for all the help folks! Hopefully everything will be alrigt soon.
/iarkin out - hopefully |
|
Back to top |
|
|
devon l33t
Joined: 23 Jun 2003 Posts: 943
|
Posted: Mon Sep 15, 2003 4:03 am Post subject: |
|
|
I would double-check with your DNS provider.
Code: | $ whois kihlberg.org | egrep "Name Server"
Name Server:DNS1.PUBLIC-DNS.NET
Name Server:DNS2.PUBLIC-DNS.NET
Name Server:DNS3.PUBLIC-DNS.NET
$ host www.kihlberg.org DNS1.PUBLIC-DNS.NET
Using domain server:
Name: DNS1.PUBLIC-DNS.NET
Address: 216.226.141.40#53
Aliases:
Host www.kihlberg.org not found: 3(NXDOMAIN)
$ host www.kihlberg.org DNS2.PUBLIC-DNS.NET
Using domain server:
Name: DNS2.PUBLIC-DNS.NET
Address: 216.226.141.42#53
Aliases:
Host www.kihlberg.org not found: 3(NXDOMAIN)
$ host www.kihlberg.org DNS3.PUBLIC-DNS.NET
;; connection timed out; no servers could be reached |
One that works
Code: | $ host kihlberg.org DNS2.PUBLIC-DNS.NET
Using domain server:
Name: DNS2.PUBLIC-DNS.NET
Address: 216.226.141.42#53
Aliases:
kihlberg.org has address 212.31.164.150 |
|
|
Back to top |
|
|
|