W
W
WebforSelf2022-04-08 08:38:33
Apache HTTP Server
WebforSelf, 2022-04-08 08:38:33

Redirect in apache2?

Tell me, there is a
Main site
https://www.site.ru

Accordingly, you need
1 - from www to without www
2 - and from http to https

in htaccess I have

RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]

RewriteCond %{HTTPS} =off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

RewriteCond %{HTTP_HOST} ^www.site.ru\.index\.php?module=MainView&page_url=
RewriteRule ^(.*)$ https://www.site.ru/ [R=permanent,L]

624fc9c4a615a795757458.png

Where does the 302 redirect come from?
And like this
In general, a 302 redirect occurs with http
624fc9dc3ddbc483381255.png
As a result, I got into the Apache config
in default.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
<VirtualHost *:80>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

There is such a redirect. Is it possible to remove it and set up a redirect only through htaccess? How to properly set up a redirect in Apache.
Tried this option
RewriteEngine On
RewriteCond %{HTTP_HOST} ^сайт\.ru$ [NC]
RewriteRule ^(.*)$ https://www.сайт.ru/$1 [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Doesn't solve the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-04-08
@WebforSelf

Where does the 302 redirect come from?

In default.conf is this
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Without explicitly specifying the R=301 flag, the response code will be 302.
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}  [L,R=301]
Or completely remove and configure the redirect only through .htaccess

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question