Apache redirection when browsing non-www of domain (just http://domain.com/)


A serious issue is occurring for a client of mine who is using Virtualmin Pro.

After creating a new virtual server, and installing Wordpress using the install script, the site cannot be browsed if only using the non-www domain name. If you browse to www.domain.com, then you land on the Wordpress setup page. Conversely, if you browse to http://domain.com/, then a 301 is issued with the location header set to http://other-domain.com. The browser then obviously redirects to other-domain.com.

I have tested a few things already:

  • DNS is set correctly at the DNS registrar for this domain - there are *, @ and other subdomain records.
  • It is not Wordpress. I have tested this by removing Wordpress and, with Wordpress still installed, renaming index.php, and replacing it with an index.html file. The same behaviour occurs regardless of what's installed in /home/domain/public_html.
  • There is no .htaccess file specifying this type of URL re-write, and /etc/httpd/cond/httpd.conf seems only to contain valid, "clean" definitions of the virtual servers
  • It is something to do with Apache. I say this because if you browse to:
    • http://domain.com/, then you are redirected to another site (other-domain.com) on the server. other-domain.com is not the default site.
    • http://domain.com/index.php, you see the required page
    • http://www.domain.com/, you see the required page
    • and the same is true of http://www.domain.com/index.php.
  • This appears to be only a problem when you are visiting the root domain, without a file.
  • I have tested the HTTP headers using CURL. We get a 200 if browsing www.domain.com, www.domain.com/index.php and domain.com/index.php. We only get a 301 if browsing domain.com/
  • If I create a virtual server for third-domain.com, I do not get these problems.

I can see that this strongly suggests a rewrite rule is at play somewhere. However, this issue seems to recur - we have deleted and re-created the virtual server, and the same behaviour persists. It's almost as is Apache has a special "fondness" for this domain.com.

Could you recommend the best steps to take next and/or assist with diagnosing this problem please?




Howdy -- it sounds like you've done a pretty thorough job there already... I don't have any immediate thoughts that come to mind as to what might be causing that.

Is there any chance I could log into the system and take a look?

If that's okay, you can either email root login details to eric@virtualmin.com, or enable Remote Support in the Virtualmin Support module.

Also, I would need to know the name of the domain that you're having these problems with.

If I logged into your system, I think the first thing I would do is review the "VirtualHost" block for this particular domain in /etc/httpd/conf/httpd.conf, just to make sure nothing looks out of the ordinary. If a Virtual Server owner were to configure a redirect, it would go in the Apache config there.

You're of course welcome to take a peek there first though and see if anything stands out to you.



I would really appreciate if you could take a look. I have a tendancy to ignore the obvious, so another pair of eyes on this issue would be really helpful!

My preference is to enable the remote support within Virtualmin rather than have root pw travel on email. Let me know if you need any other info.

I'm assuming you can tell from the recent licence registration on our account which IP address etc you need to be looking at...?


Once you enable Remote Support, it'll send us an email notifying us that it's enabled, including the external IP address that can be used to access it.

There's details on how to install and enable that here:


If you've already enabled it, then we're probably just waiting for the notification email to get past the greylisting here.

If you could let us know what domain it is that you're having problems with, that would be great. Thanks!


I've enabled remote support as required. Your ssh public keys were added.

Regarding the domain, I emailed that to you as I wasn't sure if this bug page was public/private.

Thanks, Steve

Hmm, while I do see it performing a redirect when I browse to domain.com -- it always redirects to www.domain.com.

I haven't seen it redirecting to an incorrect site.

Is it possible that you've corrected the issue here, and that when you see the incorrect site, that's due to a browser cache problem?

You may want to try accessing it with another browser, or clearing your browser cache, to see if that makes a difference.

Oh jeez... sorry to take your time up.

I think what has happened was that:

a) my browser cache (and network proxy) was keeping the 301 b) I think that there was originally an incorrect setting in Wordpress which issued this 301, pointing the redirect to the wrong domain. So no manner of .htaccess changes etc made any difference.

Once I'd cleared my cache/proxy, I then got the 301 that goes from domain.com to www.domain.com just as you did. As I was testing behind a proxy, cURL also reported the misleading result.

Wordpress allows you to change the default URL, so I have changed that from www.domain.com to domain.com, and now the 301 works in the other direction - as desired.

Thanks for your fast response.