WordPress.org

Ready to get started?Download WordPress

Forums

301 redirect from www to non-www has no effect (4 posts)

  1. mamulea
    Member
    Posted 3 years ago #

    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 ^(.*)$ http://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?

  2. Try putting the www redirect ABOVE the wordPress calls.

  3. mamulea
    Member
    Posted 3 years ago #

    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?

  4. Try this one:

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

    Some servers like different formats :/

Topic Closed

This topic has been closed to new replies.

About this Topic