htaccess does not work for wp super cache plugin

Asked

Viewed 216 times

0

I installed the wp plugin super cache for wordpress on the server and it’s working fine. But I can’t understand why my rules on . htaccess does not work for the homepage.

I rewrite the requests pro Ubdomain www to a folder with a wordpress installation, www/. htaccess:

# www (blog)
RewriteCond %{HTTP_HOST}% ^www\.domain\. [NC]
RewriteCond %{REQUEST_URI} !^/wp_inspiracoes/
RewriteCond %{REQUEST_URI} !^/index\.php/
RewriteCond %{REQUEST_URI} !^/css/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_URI} !^/fonts/
RewriteCond %{REQUEST_URI} !^/img/
RewriteRule ^(.*) /wp_inspiracoes/$1 [L]

# Rewrite all other URLs to index.php/URL (in house app)
RewriteRule .* index.php/$0 [PT]

And at www/wp_inspiracoes/. htaccess:

RewriteBase /

#full page cache
RewriteCond %{DOCUMENT_ROOT}/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/$1index-https.html -f
RewriteRule ^(.*) "/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/$1index-https.html" [L]

# BEGIN WordPress
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

These rules work for accesses like www.domain.com/some-post/ and www.domain.com/other-post/ and rewrites to the statistic local files generated by wp super cache plugin:

.../wp-content/cache/supercache/www.domain.com/index-https.html
.../wp-content/cache/supercache/www.domain.com/algum-post/index-https.html
.../wp-content/cache/supercache/www.domain.com/outro-post/index-https.html

But they DO NOT work for www.domain.com (homepage), which should rewrite for .../supercache/www.domain.com/index-https.html

So I tried some homepage-specific rules on www/wp_inspiracoes/. htaccess (before the general cache rules but they didn’t work):

# homepage rules
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{DOCUMENT_ROOT}/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html -f
RewriteRule ^(.*) "/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html" [L]

# full page cache here

I tried several rules for home but they didn’t work either:

# homepage rules
RewriteCond %{DOCUMENT_ROOT}/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html -f
RewriteRule ^$ "/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html" [L]

# full page cache here

Even these rules in www/. htaccess (before the rules rewriting www to wp_inspiracoes folder) also did not work

>     RewriteCond %{HTTP_HOST}% ^www\.domain\. [NC]
>     RewriteCond %{REQUEST_URI} ^/$
>     RewriteCond %{DOCUMENT_ROOT}/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html
> -f
>     RewriteRule ^(.*) "/wp_inspiracoes/wp-content/cache/supercache/%{SERVER_NAME}/index-https.html"
> [L]
>     
>     # www to /wp_inspiracoes rules here

If anyone can please help me with these rules, to work for both homepage (/) and posts (/some-post) Duvida_sobre_htacces_SO_ptBR.txtAbrir Showing Duvida_sobre_htacces_so_ptbr.txt.

  • There is a very strange text there in the question, are you sure you did the right copy/Paste?

1 answer

0

First the wordpress code on htacess:

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

Only after this adds your supercache rules :

# INICIO WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
AddDefaultCharset UTF-8
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/index.html.gz [L]

RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP:Cookie} !^.*(comment_author_|wordpress|wp-    postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/index.html [L]
</IfModule>
# Final WPSuperCache

Rules to add in /home/****/public_html/wp-content/cache/. htaccess

# BEGIN supercache
<IfModule mod_mime.c>
  AddEncoding gzip .gz
  AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
  SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
  Header set Cache-Control 'max-age=300, must-revalidate'
</IfModule>
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html A300
</IfModule>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.