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.

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
esmitex
  • 111
  • 3
  • I have searched this already and I always have the same problem. That's actually one of the solution I found online. –  Oct 26 '13 at 17:15

2 Answers2

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).

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).

fredden
  • 393
  • 1
  • 10
  • 1
    That fixed my problem. Now wordpress seems to be working fine. Thanks –  Oct 26 '13 at 19:39