WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] non-www to www redirects not working (3 posts)

  1. Mike Davis
    Member
    Posted 3 years ago #

    Hello,

    I am using W3 Total Cache with WordPress 2.9.2 and just noticed that when i go to the non-www URL of my site (mysite.com), it no longer redirects to the "www" version of my site (www.mysite.com). The redirect worked fine before installing W3 Total Cache.

    I noticed in another help thread that someone put the following code at the top of their .htaccess file to resolve this issue:

    'RewriteCond %{HTTP_HOST} ^DOMAIN.com$ [NC]
    RewriteRule ^(.*)$ http://www.DOMAIN.com/$1 [R=301,L]'

    Is this the right way to handle the redirect no longer working? Is there another way to do this that I am missing?

    Thanks!

  2. Mike Davis
    Member
    Posted 3 years ago #

    Nevermind. After extensive searching I found out how to do it.

    This order of rules within your .htaccess file is VERY important. Use the following structure when listing your rules (which means the rewrite rules go above the W3TC rules):

    Custom Rules

    W3TC Rules

    WordPress Rules

    Also, you have to use the correct rewrite code within .htaccess. The following is what I use for our MediaTemple hosting, per the MediaTemple knowledgebase. I tried another suggestion and got into a 301 redirect loop, so I went with what MediaTemple told me (funny how that works)! Note: replace "example" with your URL. Note2: I put the rewrite code within an <IfModule> as shown below per a suggestion from Frederick in another post. Not sure if this is necessary, but it seems to work, so I am leaving it.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
    </IfModule>

  3. Tache Madalin
    Member
    Posted 3 years ago #

    Thanks, that helped me out too :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic