Answer the question
In order to leave comments, you need to log in
How to get rid of double redirect in htaccess?
Hello. I have code in htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# С http на https
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [L, R=301]
# Со страниц с окончанием .html на без .html и слешем на конце
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1/ [L, R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
$currect_url = $_SERVER['SCRIPT_URI'];
if ( strpos($currect_url, 'https') === false ) {
$currect_url = str_replace("http", 'https', $currect_url);
$check = true;
}
if ( strpos($currect_url, '.html') !== false ) {
$currect_url = str_replace(".html", '/', $currect_url);
$check = true;
}
if( isset($check) ){
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $currect_url);
exit();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question