Redirect Loop with W3 Total Cache and non-WWW Redirect
-
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 https://www.mydomain.com. To do that, I’ve implemented the following rule.
# Redirect non-www urls to www RewriteCond %{HTTP_HOST} ^mydomain.com RewriteRule ^(.*)$ https://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] </IfModule> # 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 ^(.*)$ https://www.mydomain.com/$1 [R=301,L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # 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:
https://www.mydomain.com/wp-content/cache/page_enhanced/mydomain.com/_index.html_gzipI don’t know enough about editing htaccess files to see what I’m doing wrong here.
- The topic ‘Redirect Loop with W3 Total Cache and non-WWW Redirect’ is closed to new replies.