K
K
kosar912016-05-18 08:02:36
htaccess
kosar91, 2016-05-18 08:02:36

Why is 301 redirect not working on HTTPS?

It is required to make a redirect from www to a site without www, as well as from HTTP to HTTPS. I wrote the following:

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

To www.site.ru - redirect works
To site.ru - redirect works
To https://www.site.ru - doesn't work, and no RewriteRules work either
On https://site.ru - all RewriteRules work

It looks like mod_rewrite is turned off, but phpinfo() shows the opposite, and on https://site.ru - everything works. What could it be?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kosar91, 2016-05-18
@kosar91

Found what the problem was. As I suspected, apache didn't see the .htaccess file. But he did not see it because of the AllowOverride None directive. The sysadmin has created several host configuration files for apache, almost the same except for this directive. A site from https://site.ru was loaded by one configuration file, and https://www.site.ru by another, in which the AllowOverride directive was disabled.

D
Dmitry Bezverkhy, 2016-05-18
@dboriginal

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]

V
Viktor Taran, 2016-05-18
@shambler81

1 you don't have nginx PHP-FPM at the same time? in this version, the rewrite mod does not suit you in principle.
2. why flies and cutlets separately.
Two tasks, two rules.
Debug individually.
3. you have nginx + apache, moreover, communication between them occurs only via http with a redirect to nginx to http, as a result, you have an Apache cycle driving to https nginx to http
4. There are overriding rules.

H
heike, 2018-12-07
@heike

Why does some of the directive work and some don't?
The one at the beginning works. For example, all categories work, but https and one more stopped.
If rearranged in order, then the first one will work, and the rest will stop.
What could be the issue here? Does anyone have any ideas?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question