Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

migrated from superuser.com Oct 27 '13 at 16:57

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

    
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

2 Answers 2

up vote 1 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} !=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).

share|improve this answer
1  
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} ^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).

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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