• I have recently migrated from multiple wordpress to multisite and I have also changed the main domain (therefore I have a brand new website). Everything seems to work fine except the www to non-www redirect. After reading a lot of stuff, I tried different methods of accomplishing this but it still doesn’t do it.

    I contacted the hosting service (they have no CPanel installed so every time I have a problem I have to contact them and hope they will resolve it) and they said everything is ok on their back-end so it must be something with the 301 redirect. My previous domain was also hosted on the same server and the redirection worked fine. Even now, it redirects from both de www and the non-www version of the old domain to the non-www version of the new one, just as it should. The only thing that does not work is redirecting the www to non-www on the new domain.

    This is how my htaccess looks like (guess this is pretty standard):

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]

    I’ve been tryin to add this after de “RewriteEngine On” line:

    RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
    RewriteRule ^(.*)$ https://domain.tld/$1 [R=301,L]

    (of course, using the right domain and tld).

    Is there anything I should do different? Is there something I should ask the hosting agency?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Try putting the www redirect ABOVE the wordPress calls.

    Thread Starter mamulea

    (@mamulea)

    I’ve already done that and nothing. I tried to insert the two lines of code everywhere in the .htaccess file with the same result. Is it possible something is wrong with the server? Is there anything else I can try?

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    Try this one:

    RewriteEngine on
    RewriteCond %{HTTP_HOST}   !^$
    RewriteCond %{HTTP_HOST}   !^your-domain.com [NC]
    RewriteRule ^/(.*)         https://your-domain.com/$1 [L,R=301]

    Some servers like different formats :/

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘301 redirect from www to non-www has no effect’ is closed to new replies.