-3

When I enter the url it will redirect to http://www.xyz.in, but if I edit it to https://www.xyz.in, the SSL certificate starts working.

The problem is how to redirect to https://www.xyz.in when the user enters xyz.in

Config file:

$root = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$config['base_url'] = $root;

.htaccess file:

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?xyx.in
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

I have tried changing RewriteCond %{HTTPS} off to on, but it always redirects to http://xyz.in.

Nick
  • 4,820
  • 18
  • 31
  • 47
  • 1
    Does this answer your question? [How to redirect all HTTP requests to HTTPS](https://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https) – Example person Apr 24 '20 at 09:28

2 Answers2

0
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}

I think changing (.*) to ^ should work out. Let me know if it doesn't. Also, make sure mod_rewrite is enabled. Clear your browser's cache and try this.

Example person
  • 3,198
  • 3
  • 18
  • 45
0
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?xyz\.in
RewriteRule ^(.*)$ https://www.xyz.in/$1 [R=301,L]

Try this out. It should work.

Niraj Kumar
  • 38
  • 1
  • 5