Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have been trying to set a 301 redirect from a non www to a www domain since yesterday but it only cause problems on my site. I first tried it from the control panel of the website, then by modifying the .htaccess file with the following:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

My site is based on wordpress, the first problem that occurred was that I could not access my backend anymore… when I was trying to log in the page would just reload itself and then there was an endless loop and the whole site was unaccessible. After removing these few lines, everything was fine.

share|improve this question

migrated from Oct 27 '13 at 16:57

This question came from our site for computer enthusiasts and power users.

marked as duplicate by MadHatter, Jenny D, Massimo, HBruijn, masegaloeh May 7 '15 at 11:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

I have searched this already and I always have the same problem. That's actually one of the solution I found online. – esmitex Oct 26 '13 at 17:15
up vote 2 down vote accepted

We use something like this, which uses an exact string match, rather than a regular expression. You can change the domain to what you like. We don't include the www prefix unless our customer can't configure their DNS properly.

RewriteEngine On
RewriteCond %{HTTP_HOST} !
RewriteRule (.*)$1 [R=301,L]

It sounds like you may need to change the URL that Wordpress has configured before adding this redirect though, as Wordpress is a little touchy about having its URL changed without it being told first (and both URLs working at the time of change).

share|improve this answer
That fixed my problem. Now wordpress seems to be working fine. Thanks – esmitex Oct 26 '13 at 19:39

Looks like you have some extra characters in there to me, probably should look like:

RewriteCond %{HTTP_HOST} ^$
RewriteRule (.*)$1 [R=301,L]

The differences are minor, but should do the trick (that's how mine is set-up, anyway).

share|improve this answer
I've just tried this one and I have the same issue with wordpress. – esmitex Oct 26 '13 at 19:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.