WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] painfully slow 301 redirect from .htaccess (trailing slash) (7 posts)

  1. andrewmills
    Member
    Posted 1 year ago #

    Hi, everyone

    I've been wrestling with a slow loading WordPress multisite. I've installed and configured W3T Cache . . . and although that has helped somewhat, the real culprit seems to be the 301 redirect in the .htaccess file that adds the trailing slash to a URL. It's adding anywhere from 8 to 12 seconds to the download time before any output gets sent to the client's browser.

    I could be wrong, but I'm basing that opinion on the two pingdom tests on the same URL, both with and without the trailing slash. See below for links:

    1st theme, with W3T cache & cloudflare, with trailing slash:
    http://tools.pingdom.com/fpt/#!/OaJoO3725/http://gnswebsvcs.com/1sttheme/

    1st theme, with W3T cache & cloudflare, no trailing slash:
    http://tools.pingdom.com/fpt/#!/98Drbm9J/http://gnswebsvcs.com/1sttheme

    I've tried discussing with the webhost provider, and their suggestion was to activate CloudFlare. Now I'm a big fan of CloudFlare and use it on other sites, but that doesn't seem to be addressing the real problem in this particular instance, as far as I can tell.

    Is there a trick to optimizing .htaccess files that I'm not aware of? Or can they be cached somehow for faster performance? Or do I have conflicting/redundant settings that I can/should remove?

    Here's a copy of my .htaccess (sorry about the length):

    # Use PHP5 Single php.ini as default
    AddHandler application/x-httpd-php5s .php
    
    # BEGIN GZIP
    <ifmodule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
    </ifmodule>
    # END GZIP
    
    # BEGIN W3TC Browser Cache
    <IfModule mod_mime.c>
        AddType text/css .css
        AddType application/x-javascript .js
        AddType text/x-component .htc
        AddType text/html .html .htm
        AddType text/richtext .rtf .rtx
        AddType image/svg+xml .svg .svgz
        AddType text/plain .txt
        AddType text/xsd .xsd
        AddType text/xsl .xsl
        AddType text/xml .xml
        AddType video/asf .asf .asx .wax .wmv .wmx
        AddType video/avi .avi
        AddType image/bmp .bmp
        AddType application/java .class
        AddType video/divx .divx
        AddType application/msword .doc .docx
        AddType application/vnd.ms-fontobject .eot
        AddType application/x-msdownload .exe
        AddType image/gif .gif
        AddType application/x-gzip .gz .gzip
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        AddType application/vnd.ms-access .mdb
        AddType audio/midi .mid .midi
        AddType video/quicktime .mov .qt
        AddType audio/mpeg .mp3 .m4a
        AddType video/mp4 .mp4 .m4v
        AddType video/mpeg .mpeg .mpg .mpe
        AddType application/vnd.ms-project .mpp
        AddType application/x-font-otf .otf
        AddType application/vnd.oasis.opendocument.database .odb
        AddType application/vnd.oasis.opendocument.chart .odc
        AddType application/vnd.oasis.opendocument.formula .odf
        AddType application/vnd.oasis.opendocument.graphics .odg
        AddType application/vnd.oasis.opendocument.presentation .odp
        AddType application/vnd.oasis.opendocument.spreadsheet .ods
        AddType application/vnd.oasis.opendocument.text .odt
        AddType audio/ogg .ogg
        AddType application/pdf .pdf
        AddType image/png .png
        AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
        AddType audio/x-realaudio .ra .ram
        AddType application/x-shockwave-flash .swf
        AddType application/x-tar .tar
        AddType image/tiff .tif .tiff
        AddType application/x-font-ttf .ttf .ttc
        AddType audio/wav .wav
        AddType audio/wma .wma
        AddType application/vnd.ms-write .wri
        AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
        AddType application/zip .zip
    </IfModule>
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType text/css A691200
        ExpiresByType application/x-javascript A691200
        ExpiresByType text/x-component A691200
        ExpiresByType text/html A691200
        ExpiresByType text/richtext A691200
        ExpiresByType image/svg+xml A691200
        ExpiresByType text/plain A691200
        ExpiresByType text/xsd A691200
        ExpiresByType text/xsl A691200
        ExpiresByType text/xml A691200
        ExpiresByType video/asf A691200
        ExpiresByType video/avi A691200
        ExpiresByType image/bmp A691200
        ExpiresByType application/java A691200
        ExpiresByType video/divx A691200
        ExpiresByType application/msword A691200
        ExpiresByType application/vnd.ms-fontobject A691200
        ExpiresByType application/x-msdownload A691200
        ExpiresByType image/gif A691200
        ExpiresByType application/x-gzip A691200
        ExpiresByType image/x-icon A691200
        ExpiresByType image/jpeg A691200
        ExpiresByType application/vnd.ms-access A691200
        ExpiresByType audio/midi A691200
        ExpiresByType video/quicktime A691200
        ExpiresByType audio/mpeg A691200
        ExpiresByType video/mp4 A691200
        ExpiresByType video/mpeg A691200
        ExpiresByType application/vnd.ms-project A691200
        ExpiresByType application/x-font-otf A691200
        ExpiresByType application/vnd.oasis.opendocument.database A691200
        ExpiresByType application/vnd.oasis.opendocument.chart A691200
        ExpiresByType application/vnd.oasis.opendocument.formula A691200
        ExpiresByType application/vnd.oasis.opendocument.graphics A691200
        ExpiresByType application/vnd.oasis.opendocument.presentation A691200
        ExpiresByType application/vnd.oasis.opendocument.spreadsheet A691200
        ExpiresByType application/vnd.oasis.opendocument.text A691200
        ExpiresByType audio/ogg A691200
        ExpiresByType application/pdf A691200
        ExpiresByType image/png A691200
        ExpiresByType application/vnd.ms-powerpoint A691200
        ExpiresByType audio/x-realaudio A691200
        ExpiresByType image/svg+xml A691200
        ExpiresByType application/x-shockwave-flash A691200
        ExpiresByType application/x-tar A691200
        ExpiresByType image/tiff A691200
        ExpiresByType application/x-font-ttf A691200
        ExpiresByType audio/wav A691200
        ExpiresByType audio/wma A691200
        ExpiresByType application/vnd.ms-write A691200
        ExpiresByType application/vnd.ms-excel A691200
        ExpiresByType application/zip A691200
    </IfModule>
    <IfModule mod_deflate.c>
        <IfModule mod_setenvif.c>
            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        </IfModule>
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        </IfModule>
        <IfModule mod_filter.c>
            AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
        </IfModule>
    </IfModule>
    <FilesMatch "\.(css|js|htc|CSS|JS|HTC)$">
        FileETag None
        <IfModule mod_headers.c>
             Header set X-Powered-By "W3 Total Cache/0.9.2.4"
        </IfModule>
    </FilesMatch>
    <FilesMatch "\.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|XML)$">
        FileETag None
        <IfModule mod_headers.c>
             Header set X-Powered-By "W3 Total Cache/0.9.2.4"
        </IfModule>
    </FilesMatch>
    <FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EOT|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SVG|SVGZ|SWF|TAR|TIF|TIFF|TTF|TTC|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
        FileETag None
        <IfModule mod_headers.c>
             Header set X-Powered-By "W3 Total Cache/0.9.2.4"
        </IfModule>
    </FilesMatch>
    # END W3TC Browser Cache
    # BEGIN W3TC Page Cache core
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteRule ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 [L]
        RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9\-\.]+\.[a-z]+)\.?(:[0-9]+)?$
        RewriteRule .* - [E=W3TC_DOMAIN:%2]
        RewriteCond %{REQUEST_URI} ^/(test-league|jc|testdomain|groupnet|jcollins|collins|preset-2|preset-3|pwpolicy|pwpolicy2|pwpolicy4|pwpolicy3|jaron|gnswebdemo|demo|3rdtheme|2ndtheme|1sttheme|jaroncollins|melodytess|gnslite|fasa|webdemo|fasareplica|gnslitereplica|greencardc|roletest|fasa2|example|siteadmin|admintest|troubleshooting|gnslite2|testone|testtwo|testthree|pizazz|text|1stthemereplica|greencardc2|greencardc3)/
        RewriteRule .* - [E=W3TC_BLOGNAME:%1.]
        RewriteCond %{HTTP:Accept-Encoding} gzip
        RewriteRule .* - [E=W3TC_ENC:_gzip]
        RewriteCond %{REQUEST_METHOD} !=POST
        RewriteCond %{QUERY_STRING} =""
        RewriteCond %{HTTP_HOST} =gnswebsvcs.com
        RewriteCond %{REQUEST_URI} \/$ [OR]
        RewriteCond %{REQUEST_URI} (sitemap(_index)?\.xml(\.gz)?|[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?) [NC]
        RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php) [NC,OR]
        RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC]
        RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC]
        RewriteCond %{HTTP_USER_AGENT} !(W3\ Total\ Cache/0\.9\.2\.4) [NC]
        RewriteCond "%{DOCUMENT_ROOT}/wp-content/w3tc-%{ENV:W3TC_BLOGNAME}%{ENV:W3TC_DOMAIN}/pgcache/%{REQUEST_URI}/_index%{ENV:W3TC_UA}%{ENV:W3TC_REF}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" -f
        RewriteRule .* "/wp-content/w3tc-%{ENV:W3TC_BLOGNAME}%{ENV:W3TC_DOMAIN}/pgcache/%{REQUEST_URI}/_index%{ENV:W3TC_UA}%{ENV:W3TC_REF}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" [L]
    </IfModule>
    # END W3TC Page Cache core
    
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    # END WordPress

    Thanks in advance for any insights.

  2. It shouldn't be taking 8-12 seconds to parse the / - That should be near instantaneous.

    Your site is incredibly slow either way, though.

    W3TC isn't turned on. If it was, it would have some diagnostics in the source code.

  3. andrewmills
    Member
    Posted 1 year ago #

    Hi, Ipstenu. Thank you for the reply.

    > W3TC isn't turned on. If it was, it would have some diagnostics in the source code.

    I could easily be doing something wrong, but the plugin says it's enabled in green letters on the General Settings tab.

    Is there a parking brake I need to release somewhere? ;)

    Kidding aside-- I'll go back and take a second look at the installation instructions. Maybe I missed a checkbox or something.

    > It shouldn't be taking 8-12 seconds to parse the / - That should be near instantaneous.

    Yes, I know. And I'm thinking neither CloudFlare nor W3T Cache will help improve that situation.

    Any suggestions about how I might streamline or sequence the .htaccess file . . . or is it time to start searching for a better webhost?

  4. Usually W3TC has a 'preview' mode that you have to turn off.

    Go to /wp-admin/admin.php?page=w3tc_general

    The green 'enabled' will be there, even if you have nothing checked, so make sure you've checked at least 'page cache.'

    http://gnswebsvcs.com/readme.html doesn't take too terribly long to load, so I'd start with turning off all the plugins and switching to the TwentyEleven theme. See how it loads.

    It's possible you don't have enough PHP memory going on, which ... hard to poke at from this end.

  5. andrewmills
    Member
    Posted 1 year ago #

    It's looking like the theme is somehow responsible. (Which baffles me because I thought the .htaccess file was more of an Apache thing than a WordPress or WordPress theme thing.)

    Basically, we switch the theme to TwentyEleven, and it loads everything in under 5 seconds. We switch it to the regular theme and just the trailing slash rewrite takes longer than that. But proving it definitively is beyond my current skills/tools.

    I guess I need to find some kind of PHP debug tool that will let me do a step debugging walk through. Or am I barking up the wrong tree?

  6. *sigh* Themes.

    The short version is that themes can add in functions to your site which can totally do this. Just like plugins. I suspect it's overwriting the normal behavior.

    What theme is this?

  7. andrewmills
    Member
    Posted 1 year ago #

    A child theme based on the Headway Base. I've put an entry on their support forums, and they are looking into it.

    Sorry to have taken your time-- I knew themes could slow things down in general on WordPress, but I didn't know they could operate as early as the .htaccess point of things in the sequence.

    Clearly I still have lots more to learn about WordPress. Think I'll try to get that debugger tool running this weekend, if I can.

    Thank you again for your time.

Topic Closed

This topic has been closed to new replies.

About this Topic