I want to redirect all request to https://www.example.com.
htaccess code :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
my current code working fine but when someone enter http://example.com it taking two 301 redirect means first it redirect to https://example.com and than to https://www.example.com
I want http://example.com to https://www.example.com with one 301 redirect.
CodePudding user response:
You can use the following to redirect all requests to https://www in a single request
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{HTTP_HOST} ^(?:www\.)?(. )$
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301]
Make sure to crear your browser cached data before testing this new redirect.
