.htaccess https重写错误重定向循环


.htaccess https rewrite error redirection loop

我的.htaccess代码在chrome浏览器中给我一个错误This webpage has a redirect loop

有人能更正我的.htaccess代码吗?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^purchase'.com'.au$ [OR]
RewriteCond %{HTTP_HOST} ^www'.purchase'.com'.au$
RewriteRule ^(.*)$ "https':'/'/purchase'.com'.au'/$1" [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^'.]+)$ $1.php [NC,L]
DirectoryIndex index.html index.php

如果我的网站地址是purchase.com.au,我需要它重定向到https://purchase.com.au

试试这个:

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

基本上,它所做的是检查https是否关闭(请求是通过http-没有https发出的),并将每个请求重定向到https变体(相同的url只是转到https而不是http)

这可能会对您有所帮助!!

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www'. [NC]
RewriteRule ^(.*)$ https://purchase.com.au/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://purchase.com.au/$1 [L,R=301]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^'.]+)$ $1.php [NC,L]
DirectoryIndex index.html index.php