WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] non-www redirect fails with W3TC activated (21 posts)

  1. Mike
    Member
    Posted 3 years ago #

    Before installing W3TC, if I typed in my domain.com (without www) it would automatically redirect to http://www.domain.com. Once activating W3TC, that redirect no longer works. If I deactivate W3TC, it works again.

    With W3TC activated, if I clear all caches and try it, the first time the redirect works, but after that it doesn't. Is that normal? I know others who have W3TC and their redirect still works, so I'm confused. How do I fix this?

  2. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    It's best to move your redirects tot he top of your .htaccess file to make sure that they are processed first on requests.

  3. Mike
    Member
    Posted 3 years ago #

    Hmmm, well I haven't added any redirects myself to my .htaccess, I just see this in there:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    I moved that to above the # BEGIN W3TC Browser Cache, then cleared all caches, but the behavior remains the same. I suppose I could add something like this to my .htaccess:

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

    But I didn't think I was supposed to have to do this. IOW, I though WordPress automatically took care of that redirect, and indeed it does when W3TC is deactivated.

    I'm a bit confused on this ... what am I missing?

  4. Mike
    Member
    Posted 3 years ago #

    Well...what I showed above is the only Rewrite rules I have in my .htaccess, and I did move those to the top. So why is the redirect working with W3TC deactivated and still not working with W3TC activated?

  5. escalatoraccidnt
    Member
    Posted 3 years ago #

    Hey, I just noticed this today. I had to install W3 Total Cache on a site because according to my host my site was using to many resources.

    I'm getting the same behavior, the non www domain no longer redirects to the www.

  6. Frederick Townes
    Member
    Plugin Author

    Posted 3 years ago #

    Can anyone with this issue submit a bug submission form from the support tab of the plugin please?

  7. escalatoraccidnt
    Member
    Posted 3 years ago #

    I'm a little new at it, but I think I just submitted the bug report. Hope that helps...

    Thanks

  8. Mike
    Member
    Posted 3 years ago #

    I submitted a bug ticket as well, no response yet. I'm wanting to try CloudFlare, which from my understanding, requires this redirect to be working, so, I'm hoping to get this resolved soon. Otherwise I've been very happy with W3TC, I hate the thought of having to switch to another caching plugin!

    thanks,
    Mike

  9. Mike
    Member
    Posted 3 years ago #

    It's been a few weeks now ... any update? I didn't receive a reply from the ticket submission.

    thanks,
    Mike

  10. seriocomic
    Member
    Posted 3 years ago #

    ditto - any update?

  11. parinpatel
    Member
    Posted 3 years ago #

    I'm experiencing the same issue with my site. I just went and turned off caching for my home page under "Page Cache Settings", and the redirect works fine after that.

    But, that kinda sucks because your homepage is your most visited page. So don't want to turn that option off. :)

    Any updates on this one?

  12. Mike
    Member
    Posted 3 years ago #

    @parinpatel, did you submit a bug report from the Support section of the W3TC plugin? Any lurkers out there with the same issue, please do the same. Maybe if enough of us submit bug reports they'll look into this problem.

  13. Mike
    Member
    Posted 3 years ago #

    @seriocomic, your redirect seems to be working ... did you find a work-around, or did you just turn off page caching?

  14. parinpatel
    Member
    Posted 3 years ago #

    @mike, yup i did submit a bug report and did some further searching. looks like it was an issue with the order of the redirects in the htaccess, moving it to the top resolves the issue.

    frederick did respond to my email and indicated that it was an issue with the order on the htaccess as well, but by then i had resolved it, so didn't need to pursue it further.

    have you tried moving your redirect at the beginning of the htaccess?

  15. Mike
    Member
    Posted 3 years ago #

    Yes, as I stated in my post above, I did move my rewrite rules to the top, and yet it is still not working. I have received no response to the bug tickets I submitted.

  16. zkatkin
    Member
    Posted 3 years ago #

    Hi guys I was having the same problem, but finally fixed using the following (make sure the following is ABOVE all of the cache HTACCESS info):

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{HTTP_HOST} ^example.com
    RewriteRule (.*) http://www.example.com/$1 [R=301,L]
    </IfModule>
  17. Mike
    Member
    Posted 3 years ago #

    Yeah, I mentioned in my second post that I could add those last two lines to my htaccess as a work-around, but I thought that wasn't supposed to be necessary in WordPress. I mean, the re-direct works without those lines in my htaccess as long as W3TC is deactivated.

    Could Frederick please chime in and let me know if that's the suggested work-around, or is W3 working on a fix?

    thanks,
    Mike

  18. Mike
    Member
    Posted 3 years ago #

    OK, decided to go ahead an add the additional rewrite rules in my .htaccess as a work-around. Well, the redirect works on the home page, but not on any of the internal pages.

    Again, if I deactivate W3TC, the redirects work fine on all pages, again confirming that W3TC is the culprit.

    Also, if you deactivate W3TC and later reactivate it, it will push your rewrite rules down in your .htaccess, necessitating that you move them back up to the top again manually. (Which again doesn't fix the problem anyway so what's the point?)

    I'm trying to stay diplomatic here, but it's pretty frustrating when I'm getting no response to multiple posts and bug ticket submissions.

  19. Mike
    Member
    Posted 3 years ago #

    Got my answer (thanks Frederick, I'm sure you're a busy man). He said just to do like I stated in my second post, add this to the top of htaccess:

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

    I still don't understand why it's necessary to modify htaccess with W3TC activated, since the redirect works without those extra lines in htacess when W3TC is deactivated. Seems like that should be something that's mentioned in the documentation. Whatever, at least it's working now.

  20. DrewHammond
    Member
    Posted 3 years ago #

    Bump

    Any update on this? I just figured out this plugin was what was causing my problem today.

  21. seriocomic
    Member
    Posted 3 years ago #

    The problem most likely persists when bespoke .htaccess rewrite/redirect rules (outside of the standard WordPress one) exist in the .htaccess file. W3TC can't be expected to handle every exception.

    What I do wonder, is why it cancels the internal WP rewrite that is supposed to manage www/no-www redirection - this is something that the plugin author could work to fix.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic