1

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} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$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.

1
  • 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, 2013 at 17:15

2 Answers 2

2

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} !=example.org
RewriteRule (.*) http://example.org/$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).

1
  • 1
    That fixed my problem. Now wordpress seems to be working fine. Thanks
    – esmitex
    Oct 26, 2013 at 19:39
2

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

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

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

1
  • I've just tried this one and I have the same issue with wordpress.
    – esmitex
    Oct 26, 2013 at 19:37

Not the answer you're looking for? Browse other questions tagged .