-1

I'm trying to redirect all HTTP urls to HTTPS using the following in .htaccess:

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

However it just causes an infinite redirect loop. There is a valid SSL certificate and the website is written in asp.net in case it matters. Google chrome automatically redirects to https, but firefox and edge do not so I need to add this rule. The only way I can get the site to load in https is if I explicitly type https:// in the address. What's the possible cause here?

Jan Trindal
  • 219
  • 2
  • 9

2 Answers2

0

IIS does not support .htaccess file.so I suggest you use iis URL rewrite module and add a rule using that.

for that, you need to install the URL rewrite module by using the web platform installer or from this below link.

https://www.iis.net/downloads/microsoft/url-rewrite

than add below code in your config file:

<configuration>
 <system.webServer>
 <rewrite>
 <rules>
 <rule name="HTTP to HTTPS" enabled="true" stopProcessing="true">
 <match url="(.*)" />
 <conditions>
 <add input="{HTTPS}" pattern="off" />
 </conditions>
 <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent"/>
 </rule>
 </rules>
 </rewrite>
 </system.webServer>
</configuration>

for more detail you could refer this below link:

https://stackoverflow.com/a/55531655/11147346

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
-1

RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://yourwebsite.com/$1 [R,L]

try that

or use cloudflare to cache and perfomace your project https://support.cloudflare.com/hc/en-us/articles/115000219871-Troubleshooting-redirect-loop-errors https://community.cloudflare.com/t/cloudflare-flexible-ssl-is-it-worth-it/28043 https://developers.cloudflare.com/ssl/origin/ssl-modes/