user6224087
user6224087

Reputation:

.htaccess not redirecting http to https

I have domain www.supergenscript.com hosted on a cloud server where only an under construction index page is uploaded. There was no .htaccess file present so I created a .htaccess file and uploaded it in the server using filezilla. I want to redirect my website from http to https automatically. These are the contents of my .htaccess file.

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?supergenscript\.com
RewriteRule ^(.*)$ https://www.supergenscript.com/$1 [R=301, L]

Nothing else except these lines of codes is written there. I expected this to work but this is not redirecting my domain to https automatically. Please help me with this.

Upvotes: 0

Views: 4671

Answers (1)

Abrapata
Abrapata

Reputation: 60

You can use:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTPS} off
 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

Upload the .htaccess to your root directory.

Line 1: Checks the module - mod_rewrite is activated.

Line 2: Enables the Rewrite Engine.

Line 3: Checks if HTTPS-Protocol is switched on, if not then execute the contents of line 4.

Line 4: Redirects all requests to HTTPS via status code 301 = (permanent redirect).

Line 5: Close - mod_rewrite!

Upvotes: 2

Related Questions