skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search