-1

I need to redirect on https://domain.com

if a customer enters below URL on the browser.

  1. domain.com
  2. www.domain.com
  3. http://domain.com
  4. http://www.domain.com

I am using Codeigniter framework. Please share me, How I can manage it by changing in .htaccess.

I am using below code in .htaccess

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

    RewriteBase /demo

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
Manraj
  • 205
  • 1
  • 3
  • 10

1 Answers1

0

You can use:

RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
Croises
  • 18,570
  • 4
  • 30
  • 47
  • Thanks it's working, Please let me know Do I need to add below script also or not ? RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] – Manraj Feb 09 '17 at 12:45
  • It's related to how your site works, not the server. But I think so. Add them after the others. – Croises Feb 09 '17 at 14:15
  • 1
    As this answer solved your problem, [you should mark the answer as accepted by clicking on **tick mark** on top-left of this answer](http://meta.stackexchange.com/a/5235/160242) Thank you ! – Croises Feb 09 '17 at 14:16