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.

2
  • Possible duplicate of .htaccess redirect http to https Commented Aug 13, 2017 at 23:00
  • That should work. What is your Apache version? Commented Aug 14, 2017 at 6:14

1 Answer 1

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!

Sign up to request clarification or add additional context in comments.

4 Comments

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.. !!
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.
I see that you use Cloudflare-Nginx. If you have an error 525, the ssl handshake failed. support.cloudflare.com/hc/en-us/articles/…
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 :)