Karthik Malla
Karthik Malla

Reputation: 5800

.htaccess https rewrite error redirection loop

My .htaccess code giving me an error This webpage has a redirect loop in chrome browser.

Can anyone correct my .htaccess code?

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

If my website address is purchase.com.au and I need it to redirect to https://purchase.com.au

Upvotes: 0

Views: 1737

Answers (2)

Iansen
Iansen

Reputation: 1268

Try this:

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

Basically what it does is checkes if https is off (request was made via http - no https) and redirect every request to the https variant (same url just goes to https instead of http)

Upvotes: 3

Paresh Thummar
Paresh Thummar

Reputation: 928

This may help you !!

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

Upvotes: 0

Related Questions