1

This is the content of my .htaccess file.

I want to accomplish two things:

  1. Remove index.php from the CodeIgniter URL;
  2. Force all connections through https://

HTTPS works fine but index.php remains in the URL. How can I fix this?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
6
  • http to https rule should be at the top of your htaccess file before all internal rewrite rules.
    – Amit Verma
    Commented May 25, 2018 at 9:21
  • that means I put the if block at the end, right ? Commented May 25, 2018 at 9:22
  • 1
    Yes that's what I meant. :)
    – Amit Verma
    Commented May 25, 2018 at 9:29
  • This is a useful tool for creating a rewrite rule for your htaccess. It lets you put in what you want and where you would like it to point and it writes the rule out ... visiospark.com/mod-rewrite-rule-generator
    – Stephen
    Commented May 25, 2018 at 9:35
  • it works. Make an answer so that I can accept it. Commented May 25, 2018 at 9:36

3 Answers 3

2

Try this,

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
0

Here is working code for CodeIgniter, hope this will help

 <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

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

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

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>

Also from config.php which is in application config folder, you have to remove index.php and set it to blank

$config['index_page'] = '';
4
  • Have you updated config.php or not? You have to remove index.php from $config['index_page']. See my updated answer.
    – pspatel
    Commented May 25, 2018 at 9:30
  • I hadn't . Now I did. Commented May 25, 2018 at 9:44
  • it worked with hiccups. CSS files stopped loading. :( Commented May 25, 2018 at 9:48
  • Check URL of CSS and js, maybe it is loading with index.php.
    – pspatel
    Commented May 25, 2018 at 9:51
0

Check whether you are removing index.php from your base url after making changes to .htaccess file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.