1

I installed SSL and now I want to redirect my domain name to HTTPS . my .htaccess file has this configuration provided by my CMS

RewriteEngine On

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

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Options +FollowSymLinks
Options -Indexes

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . index.php [L,QSA]`
Neo
  • 4,640
  • 5
  • 39
  • 53

2 Answers2

1

What CMS are you using? Most common CMS have plugins which will do a better job updating any non-HTTPS resources to HTTPS.

I know you requested no referral to another link but:

The Apache docs recommend against using a rewrite: To redirect http URLs to https, do the following:

<VirtualHost *:80>
    ServerName www.example.com
    Redirect / https://www.example.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost>

This snippet should go into main server configuration file, not into .htaccess as asked in the question. This article might have come up only after the question was asked and answered, but seems to be the current way to go. https://stackoverflow.com/a/21798882/11039985

If you must use htaccess:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Update: per your response, after making a backup of the htaccess file and try:

Options +FollowSymLinks
Options -Indexes

RewriteEngine On

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

RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule . index.php [L,QSA]
mbw
  • 17
  • 3
  • i am using quickad classified and they provided this htaccess file by default but when i add ssl certificate to my domain visa vesta control panel my http links are not redirecting to https, but it works by direct https method. in my first post i have posted everything inside htaccess file so i need to redirect it . its a freshh installation. last time i have installed ssl my web site become very slow so i setup fresh installation. – PropertyFinder.Pk Feb 10 '19 at 05:31
  • Please create a backup copy of your .htaccess file and try updates response. – mbw Feb 10 '19 at 05:35
0

I think what you are looking for is setting up hsts. You can find more about this header here. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security

This link will help in setting up hsts. https://www.globalsign.com/en/blog/what-is-hsts-and-how-do-i-use-it/

himank
  • 439
  • 3
  • 5