Sergey2019-04-05 20:32:47
Web development
Sergey, 2019-04-05 20:32:47

301 redirect from www to non-www with https?

Tell me .htaccess like this:
RewriteEngine on

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

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

the task is to redirect all requests from www and without www to https
without www everything works, but with www
adds /public_html/
from that error like
Not Found
The requested URL /public_html/ was not found on this server.
help solve the problem.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Dmitry, 2019-04-05

Is there no option here? https://web-optimizator.com/301-redirekt-htaccess/

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Viktor Taran, 2019-05-16

!=on does not always work, but off more often and in general this redirect is written in dozens of ways, choose the one that suits your server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question