0

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.

1 Answers1

2

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!

Abrapata
  • 60
  • 6
  • replaced my previous code with this code.. still its not redirecting.. you can check my URL.. why its not working man I am just getting frustrated as this SHOULD WORK.. !! –  Aug 14 '17 at 16:17
  • 1
    **Calm down!** :) It's part of the job. :) I visit your site and the redirect is running fine. **Can it be that you didn't delete your cache?** If you use a Windows-System clear your cache with "**cmd**" "**ipconfig /flushdns**" and clear your Browser-Cache. If it was not, add a comment which OS (Debian 8, NGINX ...) you use and upload the htaccess to your root directory. I'll check it later. – Abrapata Aug 14 '17 at 18:03
  • I see that you use Cloudflare-Nginx. If you have an error 525, the ssl handshake failed. https://support.cloudflare.com/hc/en-us/articles/200278659-Error-525-SSL-handshake-failed – Abrapata Aug 14 '17 at 18:16
  • The redirect is now working fine because I have configured it using CloudFlare. They had an option to "Always use HTTPS" in their SSL settings which I noticed later on. I further removed that htaccess file as it was not required anymore at this moment. Thanks for your help. Your answer is correct but for a website which is normally hosted without using CloudFlare. As this will help others I will accept it. Thanks again :) –  Aug 15 '17 at 21:56