Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How to set htaccess to such examples in a Wordpress Multisite:

  • domain.com - redirect to - www.domain.com
  • sudomain.domain.com - no redirect

I have a Error 310 (net::ERR_TOO_MANY_REDIRECTS) when my .htaccess file looks like this:

RewriteEngine On 
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) wp/$1 [L]
RewriteRule ^(.*\.php)$ wp/$1 [L]
RewriteRule . index.php [L]
share|improve this question
add comment

2 Answers

Try:

RewriteEngine on
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{HTTP_HOST}   !^www\. [NC]
RewriteRule ^/(.*)         http://www.%{HTTP_HOST}/$1 [L,R=301]
share|improve this answer
add comment

I think you only need to ask explicit for %{HTTP_HOST} to be domain.com. All implicit conditions like »does %{HTTP_HOST} NOT start with www« will effect all subdomains too. So this should work for your case

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

RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) wp/$1 [L]
RewriteRule ^(.*\.php)$ wp/$1 [L]
RewriteRule . index.php [L]

Make sure, that the constant DOMAIN_CURRENT_SITE and the domain attribute (in network settings) of your root blog is set to www.domain.com. The NOBLOGREDIRECT constant might also be helpful for your purposes.

share|improve this answer
add comment

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.