Y
Y
Ysery2020-06-18 09:25:35
htaccess
Ysery, 2020-06-18 09:25:35

.htaccess collaborative rules are handled incorrectly, how to fix?

Good day, dear experts.

There is this rule:

# BEGIN WPSuperCache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#If you serve pages from behind a proxy you may want to change 'RewriteCond %{HTTPS} on' to something more sensible

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTPS} on
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html -f
RewriteRule ^(.*) "/wp-content/cache/supercache/%{SERVER_NAME}/$1/index.html" [L]
</IfModule>

# END WPSuperCache


This code takes the cached pages of the site and displays them quickly.

I tried to insert these lines of code before it (I also tried after it - the result does not change):

RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)srp=
RewriteCond %{QUERY_STRING} !(^|&)srk=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]

RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html? [L,R=301]


These rules aim to strip everything after .html except for a couple of requests or if the link has /amp/ at the end (which is an AMP page).

But in the end, when you click on any link with an article, it redirects (as an example)
https://site.ru/wp-content/cache/supercache/site.ru/statiya-o-tom-to.html/
with "too many redirects" error.

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-06-18
@Ysery

RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html? [L,R=301]

Here you need to add an exception for the folder with the cache.
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} !(^|&)srp=
RewriteCond %{QUERY_STRING} !(^|&)srk=
RewriteRule ^(.+?)\.html$ https://%{HTTP_HOST}/$1.html? [L,R=301]

RewriteCond %{REQUEST_URI} !^/wp-content/cache/
RewriteRule ^(.+?)\.html(?!/amp/).+$ https://%{HTTP_HOST}/$1.html? [L,R=301]

Put redirects above WPSuperCache rules.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question