Forum Moderators: phranque

Message Too Old, No Replies

help with www redirect in httpd.conf

         

lencholamas

8:53 pm on Feb 17, 2012 (gmt 0)

10+ Year Member



hello i'm trying to setup apache httpd.conf such that when the client types in http://domain.com it will redirect to http://www.domain.com

In my httpd.conf file, I have this written:

<Directory "/var/www/html">
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain1.com/$1 [R=301,L]
...
</Directory>

I also verified the rewrite module is loaded.

Any idea why it's not working? When I go to http://domain.com I get a could not find site error. Logs are no help either.

Thanks!

[edited by: tedster at 4:27 am (utc) on Feb 21, 2012]
[edit reason] avoid the auto-linking [/edit]

g1smd

9:05 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do both www and non-www have DNS entries?

Do both www and non-www point to the same folder as their document root?

lucy24

10:53 pm on Feb 17, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Before you start typing your answer, look at your first post. That's why we insist on "example.com". You'll see the difference. This in turn makes it a whole lot easier for other people to understand what you're asking.

phranque

2:06 pm on Feb 21, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, lencholamas!

to start with your statement mentions domain.com while your mod_rewrite directives specify domain1.com, so is there a typo/spelling problem in your test or is it just in your post?
(by the way, we use example.com here whenever possible since it remains as an unlinked url citation and this makes code and descriptions easier to read.)

also, i've never seen a "could not find site" error.
what status code was returned when you requested your http://example.com/ url or http://www.example.com/ url?

you might get useful information if you use the RewriteLog/RewriteLogLevel directives to tell the server to log any rewriting actions it performs:
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog

lucy24

8:10 pm on Feb 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The line "could not find site" sounds like a browser message, not an apache error. It means that the browser went the rounds of DNSs and nobody had heard of the domain. If the browser can only reach one version (either with or without www) then your first stop will have to be with the DNS to make sure they've got both versions pointing to the same place. It's no use putting something in your config file (or htaccess) if the request never even gets that far.

g1smd

8:18 pm on Feb 21, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The OP want to redirect requests for example.com to www subdomain.

What should happen to requests for example.com:80 and www.example.com:80 ?

These are additional non-canonical URLs.

What about example.com. and example.com.:80 too?

All are prefectly valid requests.