Ready to get started?Download WordPress


Redirect Loop with W3 Total Cache and non-WWW Redirect (1 post)

  1. hydraglyph
    Posted 9 months ago #

    Hi guys,

    I'm having a very specific problem and, while I've found many topics with similar issues, I haven't found one that helped me, so apologies is this is repetition.

    I have a Wordress install that is using W3TC.

    I need to force a redirect from non-WWW to WWW, so that all users that navigate to mydomain.com will be automatically redirected to http://www.mydomain.com. To do that, I've implemented the following rule.

    # Redirect non-www urls to www
    RewriteCond %{HTTP_HOST} ^mydomain.com
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]

    This makes sense to me, but must be conflicting with something else in my .htaccess file. Not sure whether it's with the standard Wordress entries, or the entries that have been added by W3TC.

    My entire .htaccess file looks like this:

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php
    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_METHOD} !=POST
        RewriteCond %{QUERY_STRING} =""
        RewriteCond %{REQUEST_URI} \/$
        RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
        RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" -f
        RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" [L]
    # END W3TC Page Cache core
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    # Redirect non-www urls to www
    RewriteCond %{HTTP_HOST} ^mydomain.com
    RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    # END WordPress

    Without the custom redirect code I added, everything works fine. However, when I do add it, I get a redirect error and the page redirects to this URL:

    I don't know enough about editing htaccess files to see what I'm doing wrong here.


You must log in to post.

About this Topic