C
C
campusboy2017-04-21 21:25:07
Apache HTTP Server
campusboy, 2017-04-21 21:25:07

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

But in this option, there are 2 redirects if the page http://site.ru/post.html comes across . Is it possible to write a rule for this to happen in one redirect?
PS: Temporarily made with php
$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 question

Ask a Question

731 491 924 answers to any question