WordPress.org

Ready to get started?Download WordPress

Forums

After W3 Total Cache redirect domain.de to www.domain.de does not work! (31 posts)

  1. wflorian
    Member
    Posted 4 years ago #

    Hello.

    I am using W3 Total Cache since two days. There was a redirect from http://domain.de to http://www.domain.de which does not work anymore. I asume that it is caused by the new htaccess file.

    # BEGIN W3 Total Cache
    <IfModule mod_setenvif.c>
    SetEnvIfNoCase Accept-Encoding (gzip) APPEND_EXT=.$1
    </IfModule>
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register).php|wp-.*\.php|index\.php) [OR]
    RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
    RewriteCond %{HTTP_USER_AGENT} !(bot|ia_archive|slurp|crawl|spider) [NC]
    RewriteCond /is/htdocs/wp1150069_94fgh4555K/www/mod/wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} -f
    RewriteRule (.*) wp-content/w3tc/pgcache/$1/_default_.html%{ENV:APPEND_EXT} [L]
    </IfModule>
    # END W3 Total Cache

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

    What exactly do I have to change to make the redirect work again?

    Thank you!

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. Frederick Townes
    Member
    Posted 4 years ago #

    I don't see any directives for the redirect. If they were lost you need to restore them at the top of the file.

  3. wflorian
    Member
    Posted 4 years ago #

    Actually there has not been any directives before. As far as I know WordPress redirects automatically. Unfortunately this redirect does not work anymore since there are the new lines of code from W3 Total Cache in the htaccess file.

    So I guess that the code from W3 Total Cache has to be modified to make the redirect work again.

    Any ideas?

  4. Frederick Townes
    Member
    Posted 4 years ago #

    So I guess that the code from W3 Total Cache has to be modified to make the redirect work again.

    W3TC does not change how WP handles URLs. Disable the plugin and see if the issue is resolved to confirm that the issue is W3TC.

  5. kento
    Member
    Posted 4 years ago #

    Hi,

    When i put this code on the top of my htaccess everything ok

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain.com$
    RewriteRule ^(.*) http://www.domain.com/$1 [QSA,L,R=301]

    but when W3TC update cache this code move down and problem come back :

    http://www.domain.com/wp-content/w3tc/pgcache/_default_.html.gzip when try http://domain.com

    :'(

  6. Frederick Townes
    Member
    Posted 4 years ago #

    This issue is fixed in the next release. Simply make your changes after enabling disk enhanced page cache and all will be fine for now.

  7. wflorian
    Member
    Posted 4 years ago #

    W3TC does not change how WP handles URLs. Disable the plugin and see if the issue is resolved to confirm that the issue is W3TC.

    I did what you asked me to do. I deactivated the plugin and right after doing this the redirect does work again! So it seems that W3TC does change how WP handles URLS...

    Unfortunately I tried the code posted above from "kento" and this does work for me!! Thanks!

    Just wanted to tell you, that W3TC does something with the URL handling...

  8. Frederick Townes
    Member
    Posted 4 years ago #

    It doesn't change how WP works, but it does affect other rules you may have, being that they are an unknown quantity. Yours is actually not a common issue.

  9. dagger77
    Member
    Posted 4 years ago #

    I have the same exact problem. so its common problem using 2.9.2. When i deactivate w3 all fine and non www go to www but when activating w3 total cache its stop pointing to http://www.. w3 total catch doing something with url.. anyone know any fix to this ?

  10. dagger77
    Member
    Posted 4 years ago #

    got my site fixed

    here is how for anyone who need it..
    use this code in your htaccess (make sure its on top before anything els)

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

    this simply change all non www links to www good for SEO and search engines

  11. Frederick Townes
    Member
    Posted 4 years ago #

    FYI: Search engines don't care if your site's URL contains www. or not; only consistency matters.

  12. cortex123
    Member
    Posted 4 years ago #

    Hi,

    I'm facing the same problem. The native wordpress redirection works fine with W3 off, but when it's on the http:// to http://www. redirection does not work for all urls. It only works for the main page with the rule:

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

    That is, for http://mysite.com user is redirected correctly to http://www.mysite.com, but for http://mysite.com/mypost, user is not redirected to http://www.mysite.com/mypost, instead the redirection takes him to main page.

    How to fix it Frederick?

    Thanks in advance for such a powerful plugin

  13. Frederick Townes
    Member
    Posted 4 years ago #

    When using disk enhanced mode make sure that the directives appended to that file appear directly above the pretty permalink directives for WordPress. Then move all of the other directives above the W3TC directives and all will be fine. This is better handled in the development version: http://wordpress.org/extend/plugins/w3-total-cache/download/

  14. johnclayton
    Member
    Posted 4 years ago #

    I believe the issue is that W3TC doesn't take into account different host names when it caches pages to disk. As a result, when a request comes in for domain.com, the rewrite rules send out the cached file, which is what makes it fast. The down side is that by bypassing WordPress the canonical URL functionality that would redirect to http://www.domain.com is also bypassed.

    The ideal fix would be to add the host name to the page cache root. Instead of wp-content/w3tc/pgcache/, use wp-content/w3tc/pgcache/{HOSTNAME}/. WP Super Cache does this and it works nicely - requests to domain.com are not served from the cached files for http://www.domain.com, so WordPress gets executed and redirects to the canonical URL, and there is no output to cache.

    Any chance we could see this in W3 Total Cache?

    Thanks!
    John

  15. Frederick Townes
    Member
    Posted 4 years ago #

    There is no reason to use hostname in cache path because http://www.domain.com and domain.com has same content. Redirection rules should be at the top of .htaccess

  16. Tanmaygeek
    Member
    Posted 4 years ago #

    Hi Fred,
    I'm also facing the problem with WP-3 and W3TC. I installed the development version and tried as you told in the above conversations. mydomain.com does not redirect to http://www.mydomain.com. But if I disable the home page caching then that works. But the page performance decreases. Any solution?

  17. cosmictap
    Member
    Posted 4 years ago #

    Same problem as Tanmay.

  18. Frederick Townes
    Member
    Posted 4 years ago #

    You either have to use the development release which has better handling of this case or you need to move your redirect directives about the W3TC page cache directives.

  19. Tanmaygeek
    Member
    Posted 4 years ago #

    you need to move your redirect directives about the W3TC page cache directives
    Did not understand. Please elaborate. BTW I was using the development version and the problem was still there

  20. Frederick Townes
    Member
    Posted 4 years ago #

    Then submit a bug submission form from the support tab of the plugin.

  21. befound
    Member
    Posted 3 years ago #

    Hi Fredrick,
    Thanks for making this great plugin.
    Do you still suggest moving the wordpress rewrite rules?

    I want to comment that SEO suggests only one listing of your site, http://www.domain.com or domain.com but not both.

  22. hkdigit
    Member
    Posted 3 years ago #

    Hi Fredrick,

    I already put the directives on top of W3 Total Cache section...

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

    # BEGIN W3 Total Cache

    But it still not working, if I goto http://hkgimages.com/pic, it redirect to http://www.hkgimages.com/

    I agree with befound, it not good for SEO, if redirect won't work.

    Any hints? Many thanks in advance.

  23. Frederick Townes
    Member
    Posted 3 years ago #

    You can submit a bug submission from the support tab of the plugin if you're still having an issue.

  24. JW1980
    Member
    Posted 3 years ago #

    Frederick, I think I have found a related issue. I'm trying to fix an incompatibility with WPML that hasn't been fixed yet.

    When using different domains per language, I have the following problem.
    Domains are on widgets.com and language domains are widgets.xx and xx.widgets.com, all working fine using WPML.

    Switching languages from each page works correctly, but on home, the translation is not correctly returned. I've found that it is handled by the following code in sitepress.class.php:
    echo '<script type="text/javascript">var icl_lang = \''.$this->this_lang.'\';var icl_home = \''.$this->language_url().'\';</script>' . PHP_EOL;

    The value is read from:

    addLoadEvent(function(){
        var lhid = document.createElement('input');
        lhid.setAttribute('type','hidden');
        lhid.setAttribute('name','lang');
        lhid.setAttribute('value',icl_lang);
        src = document.getElementById('searchform');
        if(src){
            src.appendChild(lhid);
            src.action=icl_home;
        }
    });

    Unfortunately something goes wrong.

    I've tried to patch it with:

    global $sitepress_settings;
    $this->this_lang = array_search('http://' . $_SERVER['HTTP_HOST'],$sitepress_settings['language_domains'])

    I noticed that with W3 Total Cache on, HTTP_HOST header reported by browser (Firefox, Chrome) is correct and the domain that is really requested.

    But HTTP_HOST header reported by $_SERVER['HTTP_HOST'] reports another domain. Usually the previous one or one that it seems to set and doesn't want to change anymore.

    I've disabled caching on the home but it persists, any direction you can give me where to look or want to debug together? ;)

    Thanks for the great plugin BTW, much appreciated!

  25. JW1980
    Member
    Posted 3 years ago #

    I noticed that W3 Total Cache is doing something with the headers in enhanced mode, I now use basic mode and this seems to have solved the issue. Frederick, it would be great if you could confirm that this could be a possible solution and maybe (we/you) can make it work for enhanced caching as well?

  26. Frederick Townes
    Member
    Posted 3 years ago #

    Do these problems continue when all other plugins are disabled? I'm not clear on what's going wrong, are you sure another plugin isn't changing the HTTP_HOST value? Does that work perfectly in disk basic, but not enhanced? What are the exact steps to duplicate?

  27. mschroettle
    Member
    Posted 3 years ago #

    Hi Frederick

    I can second JW's comments:
    I am using WPML for multi-lingual content and I am using alias domains for the different languages - imho the cleanest way to serve content in different languages...
    When I activate W3TC, the cache only ever serves up one language and it seems that it only serves up the one that is first accessed/cache page created.
    When I want to pull up cached content in another language by using the url (which has a different root domain) I only see the old content.
    I.e. if the page gets cached from ...co.uk, I see content in English, if the page first got chached from ...fr, I see content in French.
    Maybe johnclayton has the right idea to make W3TC more apt to handle multi-domain/multi language sites...
    just my 2 cents...

    btw. Everything works fine with wp-super-cache.

  28. JW1980
    Member
    Posted 3 years ago #

    Hi Frederick,

    mschroettle has explained exactly what happens for me as well. By changing from enhanced to basic the issue was resolved, do you see the same mschroettle?

  29. Frederick Townes
    Member
    Posted 3 years ago #

    btw. Everything works fine with wp-super-cache.

    Regardless of settings?

  30. seaphire
    Member
    Posted 3 years ago #

    I've tried using the development version and that does not change anything. Disabling the plugin and switching to WP Super Cache seems to be the more-practical solution at this point.

    However, I believe this has been mentioned, but you can just add this code to the top of your .htaccess file:

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

    And everything will work correctly again. HOWEVER, this does not correct the problem as WordPress is supposed to automatically redirect the URLs -- but once the plugin is enabled, it does not.

    Since WordPress 2.3 a feature called "canonical URLs" has been known to redirect www to non-www or vice-versa...

    Regardless of settings?

    FYI, WP Super Cache works just fine... well judging that its made by the WordPress Developers -- I'd hope so... anyways there's a problem that needs to be located in W3 Total Cache...

Topic Closed

This topic has been closed to new replies.

About this Topic