virtualhost rewrite rules; http://domain->http://www.doma

We're having trouble with 1 out of 7 virtualhost configurations: trying to get http://example.com to resolve to http://www.example.com.

We have 7 domains setup in linode, DNS records all configured the same, with A/AAAA records all pointing to the same linode (same IP). The DNS record is set up for the domain without www. prefix.

The linode is running Ubantu 9.1.

There are virtualhost files for all 7 domains in /apache2/sites-available, and all have been enabled via a2ensite.

Here is a template of the virtualhost file from sites-enabled, where "example" is replaced with the domain name. All sites have the same DocumentRoot (drupal multisite install).

The http://example.com-> http://www.example.com rollover is working of 6 out of the 7 domains so configured. The question, what might be the problem with the 1 that won't behave?

# Admin email, Server Name (domain name) and any alias

ServerAdmin admin@example.com

ServerName example.com

ServerAlias www.example.com

Index file and Document Root (where the public files are located)

DirectoryIndex index.html index.php

DocumentRoot /var/www/webroot

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all

RewriteEngine on

RewriteBase /

RewriteCond %{HTTP_HOST} !^www.

RewriteCond %{HTTP_HOST} !^$

RewriteCond %{SERVER_PORT} !^80$

RewriteRule ^/(.*) http://www.%{HTTP_HOST}:%{SERVER_PORT}/$1 [L,R]

RewriteCond %{HTTP_HOST} !^www.

RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Drupal

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_URI} !=/favicon.ico

RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Custom log file locations

LogLevel warn

ErrorLog /var/log/example/error.log

CustomLog /var/log/example/access.log combined

I tried deleting an recreating the DNS record.

I tried adissite disabling the site (it becomes unavailable), then reenabling (aensite) (it becomes available).

Where might I look for clues?

Thanks!

2 Replies

@nacho:

The DNS record is set up for the domain without www. prefix.
Unless this is a typo, a redirect to 'www.example.com' by the webserver for 'example.com' is not going to work unless you have a resource record (RR) pointing to a destination for www, such as a CNAME, A, or AAAA record.

What happens when you try http:///example.com from a webroswer? This information (domain not found, 404, etc) might help someone clue in on the problem at hand. Actually providing the domain(s) would allow someone to maybe diagnosing the problem, without requiring feedback from you.

My suggestions: 1) Rule out DNS: verify DNS records exist and are correct, 2) Verify the rewrite configuration is correct (not my area of expertise), 3) check your web server logs as to what is happening to the requests.

I suspect if it's a web server configuration problem, it's most likely a typo. Try copying the configuration from one of the working domains, then paste it modifying it for the not working domain.

Travis

I think the problem was that when I set up this linode, I associated the domain name with the ip address in /etc/host

127.0.0.1 localhost

173.255.192.16 example.com example

This, it think, was allowing the domain to be resolved without reference to the vhost configuration.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct