Why doesn't the 301 redirect to HTTPS?

You want to do a redirect from www to site without www and HTTP to HTTPS. Ordered the following:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://site.ru/$1 [R=301,L]

On www.site.ru - redirect is working
On site.ru - redirect is working
On https://www.site.ru - does not work, and also does not work any RewriteRule
On https://site.ru - all RewriteRule

It seems that mod_rewrite just off, but phpinfo() shows the opposite, and https://site.ru - all works. What could it be?
July 9th 19 at 13:23
3 answers
July 9th 19 at 13:25
Solution
Found what the problem was. As I expected, apache is not seeing the file .htaccess. And I did not see it because the Directive AllowOverride None. The system administrator has created multiple configuration files for apache hosts are almost the same, except the Directive. The website https://site.ru - load one configuration file, and https://www.site.ru on the other, in which the AllowOverride Directive is off.
July 9th 19 at 13:27
Try this option

AddDefaultCharset utf-8
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*) [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://site.ru/$1 [R=301,L]
Unfortunately, no change - Margret_Cummings commented on July 9th 19 at 13:30
Apparently there is a conflict with other rules .htaccess and their order, or c CMS, or tinctures servers. I double-checked the example on your website code. Strip .htaccess rules from others and verify the order, you can also check on the same hosting-but without cms, if all else fails, contact the admins of the server. ((( - Geovanny33 commented on July 9th 19 at 13:33
July 9th 19 at 13:29
1 you have both nginx PHP-FPM ? in this embodiment, the mod rewrite does not suit you in principle.
2. why flies and cutlets separately.
Two problems two rules.
Debug separately.
3. you have nginx+apache while the communication between them happens only http redirect in nginx for http, in restate you cycle drives Apache on https with nginx on http
4. There are perepravnaya rules.
Is a standard Apache + PHP. Tried 2 separate rules - did not help. If there was overlapping rules, would not have worked https://site.ru and www.site.ru. And it all works. Lean more to the server configuration. Don't know under what settings, Apache can not see the file .htaccess? - Margret_Cummings commented on July 9th 19 at 13:32
: the first option is the order of the rules .htaccess is a 99%
In General, design with op suggests that he is quite a short one correspondence and he just doesn't care about the second, which brings us back to the beginning, break like normal people BBB and https on different rules. - Geovanny33 commented on July 9th 19 at 13:35

Find more questions by tags ApachehtaccessHTTPSProcessing URL