Redirect WordPress MS to no-www version, excepting some dirs and prefixes

<IfModule mod_rewrite.c>
RewriteEngine on
   #If whe're using www.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    #prefixes to !^ ignore
RewriteCond %{REQUEST_URI} !^/host
RewriteCond %{REQUEST_URI} !^/aprobar
RewriteCond %{REQUEST_URI} !^/wp-admin
RewriteCond %{REQUEST_URI} !^/wp-login.php
    #See at the end about index.php
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 
</IfModule>

When you’re using permalinks, WordPress do something like this to get the content:

  • www.example.com/pretty-url -> www.example.com/index.php?pretty-url

So we need to avoid redirecting index.php

The new problem is that we are NOT doing this:

  • www.example.com/index.php -> example.com/index.php -> example.com/

Sure we can set a new rule at the very end of .htaccess to rewrite this particular case.