Forcing SSL for all but one directory in CodeIgniter with .htaccess Forcing SSL for all but one directory in CodeIgniter with .htaccess codeigniter codeigniter

Forcing SSL for all but one directory in CodeIgniter with .htaccess


You need to add an additional exclusion for your controller, or add a passthrough at the top. So either:

<IfModule mod_rewrite.c>  RewriteEngine On  RewriteBase /  RewriteCond %{SERVER_PORT} 80  RewriteCond %{REQUEST_URI} !^/pirate/ [NC]  RewriteCond %{REQUEST_URI} !^/index\.php [NC]  RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]  RewriteCond $1 !^(blog|images|css|js|robots\.txt|favicon\.ico)  RewriteCond %{REQUEST_FILENAME} !-f  RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^(.*)$ /index.php?/$1 [L]</IfModule>

or

<IfModule mod_rewrite.c>  RewriteEngine On  RewriteBase /  RewriteRule ^index\.php$ - [L]  RewriteCond %{SERVER_PORT} 80  RewriteCond %{REQUEST_URI} !^/pirate/ [NC]  RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]  RewriteCond $1 !^(blog|images|css|js|robots\.txt|favicon\.ico)  RewriteCond %{REQUEST_FILENAME} !-f  RewriteCond %{REQUEST_FILENAME} !-d  RewriteRule ^(.*)$ /index.php?/$1 [L]</IfModule>

The reason the redirect was happening is that the rewrite engine loops. After the original URI get routed to index.php, the rewrite engine loops again and the redirect rule gets applied and the routed URI gets redirect.