Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Apache2: how to redirect/alias www.domain.com to domain.com?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
iarkin
n00b
n00b


Joined: 04 Apr 2003
Posts: 18
Location: Left at Sirius, second star to the right

PostPosted: Sun Sep 14, 2003 5:10 pm    Post subject: Apache2: how to redirect/alias www.domain.com to domain.com? Reply with quote

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
View user's profile Send private message
Sanity1971
n00b
n00b


Joined: 13 Sep 2003
Posts: 19
Location: Holland

PostPosted: Sun Sep 14, 2003 8:24 pm    Post subject: I do it the other way around usually Reply with quote

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.

Code:
NameVirtualHost *


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
View user's profile Send private message
iarkin
n00b
n00b


Joined: 04 Apr 2003
Posts: 18
Location: Left at Sirius, second star to the right

PostPosted: Sun Sep 14, 2003 9:37 pm    Post subject: Reply with quote

Thank you very much for your quick answer! :D

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
View user's profile Send private message
devon
l33t
l33t


Joined: 23 Jun 2003
Posts: 943

PostPosted: Mon Sep 15, 2003 12:39 am    Post subject: Reply with quote

I can't get www.kihlberg.org to resolve.
Code:
$ host www.kihlberg.org
Host www.kihlberg.org not found: 3(NXDOMAIN)
$ host kihlberg.org
kihlberg.org has address 212.31.164.150
Back to top
View user's profile Send private message
iarkin
n00b
n00b


Joined: 04 Apr 2003
Posts: 18
Location: Left at Sirius, second star to the right

PostPosted: Mon Sep 15, 2003 12:48 am    Post subject: Reply with quote

oh... :oops:

*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 :D
Back to top
View user's profile Send private message
devon
l33t
l33t


Joined: 23 Jun 2003
Posts: 943

PostPosted: Mon Sep 15, 2003 4:03 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum