I have a website with https://example.com , http://example.com , https://www.example.com and https://www.example.com working fine.
Now I want that regardless of which one you type, it redirects to https://www.example.com . I am using the code below in my .htaccess (and tried many more), but after doing the redirection in the browser the page doesn't load, giving error "Too many redirects". I tried of course deleting cache.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
Since my hosting is Heroku, which has special rules, any of the other solutions didn't work for me. The following code in .htaccess worked like a charm:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
I have something Similar issue the bellow code solve problem for me
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^[DOMAIN HERE]$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Note: Replace
[DOMAIN HERE] Should be Replaced With you domain
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.