GluePear
GluePear

Reputation: 7725

Codeigniter .htaccess file for SSL inserts index.php

I'm using the following .htaccess file to redirect certain pages to https://

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]

RewriteCond $1 !^(index\.php|resources|robots\.txt|static)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

This works, except that when you go to the page that gets rewritten to https:// it also inserts index.php in the URL. Everything works fine, but I would like that index.php not to be inserted. Any ideas?

Thanks.

Upvotes: 1

Views: 3357

Answers (2)

John Y. Heo
John Y. Heo

Reputation: 1

<Directory "/home/test">
    Require all granted
    ***AllowOverride All***
    SSLOptions +StdEnvVars
</Directory>

After adding "AllowOverride All" in your apache configuration, it will work properly.

Regards.

Upvotes: 0

anubhava
anubhava

Reputation: 785296

You are missing L flag from your top 2 rules.

You can use this code:

RewriteEngine on

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

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Upvotes: 3

Related Questions