Answer the question
In order to leave comments, you need to log in
Redirect from https://www. to https:// using Apache mod_rewrite?
I'm trying to set up a simultaneous redirect from www.sitename.com to sitename.com and from http to https. The rules below work great except that there is no redirect from https://www.sitename.com to https://sitename.com . The rest of the options work.
<pre>
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</pre><br/>
<pre>
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</pre><br/>
Answer the question
In order to leave comments, you need to log in
It does not give https in .htaccess, you can catch it in php through $_SERVER['https'] .
Try this code:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
Try
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) site.ru/$1 [L,R=301]
Yes, I have encountered this. As a result, I checked the port number. Like this:
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ www.domain.tld/ $1 [L,R]
RewriteCond %{HTTPS} off
RewriteRule (.*) https ://%{HTTP_HOST}%{REQUEST_URI}
After https, remove the space (the habr parser distorts). Change %{HTTP_HOST} to your sitename.com
Try this.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
If the frontend is nginx, it may not be the https variable, so you can
RewriteCond %{HTTP_X_FORWARDED_PROTO} http
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question