Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter, force ssl on a particular page

I'm having hard time trying to force https (ssl) to particular page on codeiginiter framework. I tried many ways, but none worked. The only way worked for me is changing the $config['base_url'] site link to begin with https instead of http. The result was that all links were set to ssl (the entire site), which is none sense because I don't need to use the SSL everywhere. I used some php code in the login page, ut that made some troubles so I gave it up.

I want to know whether this is a good method how to do that, any idea?

Thanks,

like image 449
Digital site Avatar asked Aug 01 '26 16:08

Digital site


1 Answers

You need add Condition on .htaccess to make use SSL port work only for selected urls.

Here is example, how to do

RewriteEngine on

RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ https://www.yourdomain.com/controller/function[R=301,L]

RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} controller/function
RewriteRule ^(.*)$ https://www.yourdomain.com/controller/function[R=301,L]

RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L] 

P.S : Your base_url must be set to “/” in your config file. For more information check http://codeigniter.com/wiki/SSL_Handling

like image 193
safarov Avatar answered Aug 04 '26 13:08

safarov