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


i realize there's been lot of questions along these lines @ point i've read through of them , think situation unique.

i'm trying use .htaccess force https make optional 1 directory (which called pirate). i've done things before time didn't cooperate. first started code forces use https.

<ifmodule mod_rewrite.c>   rewriteengine on   rewritebase /    rewritecond %{server_port} 80   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> <ifmodule !mod_rewrite.c>   errordocument 404 /index.php </ifmodule> 

then added exception (i'm showing first rule here):

rewritecond %{server_port} 80 rewritecond %{request_uri} !^(/pirate/) [nc] rewriterule ^(.*)$ https://%{server_name}%{request_uri} [l,r=301] 

that should it! controllers should go https:

1) http://www.mysite.com/contact/ -> https://www.mysite.com/contact 

check. pirate controller should able https:

2) https://www.mysite.com/pirate/ -> https://www.mysite.com/pirate/ 

no change. perfect! lastly pirate controller should able old http:

3) http://www.mysite.com/pirate/ -> https://www.mysite.com/index.php?/pirate/ 

that's not right. still forces https , stopped hiding index.php. summarize, have 2 conditions , rule. seems if first condition true , second 1 false rule applied , second rule applied , 301 redirect returned. know sounds strange if wasn't wouldn't asking.

why happening , how fix it?

you need add additional exclusion controller, or add passthrough @ top. 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 redirect happening rewrite engine loops. after original uri routed index.php, rewrite engine loops again , redirect rule gets applied , routed uri gets redirect.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -