Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a codeignitor application running on Apache2, I have managed to remove the index.php from the urls with this .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 

now I want to make certain parts of the site redirect to https, I tried this:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L] 
RewriteRule ^/?cpanel/(.*) https://%{SERVER_NAME}/cpanel/$1 [R,L]
RewriteRule ^/?login/(.*) https://%{SERVER_NAME}/login/$1 [R,L]

But it doesn't work. I have to say when it comes to Apache rewrites im a noob. I can't find any tutorials on how to remove index.php and rewrite/redirect certain parts of the site to https.

Any ideas,

Thanks.

share|improve this question
    
Also, I think you also have a bug in your regexps. Note that https://example.com/cpanel matches the cPanel regexp, which will redirect to https://.../cpanel/cpanel, which matches the regexp, etc. –  nickgrim Oct 28 '12 at 19:23
    
@nickgrim Thanks, that was a cut and paste problem when doing the question the .htaccess is correct in that manner, edited to show this –  Shutupsquare Oct 28 '12 at 19:27
    
Ah, no, you missed my point. http://.../cpanel/foo will redirect (correctly) to https://.../cpanel/foo; however, that will then redirect to https://.../cpanel/cpanel/foo, etc. The problem is that your redirect-to-https rules should only run if it's not already using https. I think you need a RewriteCond %{HTTPS} "off" before each of those rules. –  nickgrim Oct 28 '12 at 19:32
    
@nickgrim Nick you just nailed it man! nice one!. Working a treat. –  Shutupsquare Oct 28 '12 at 19:35
add comment

1 Answer

up vote 0 down vote accepted

The [L] means "last" i.e. stop processing further rules if this rule matches. I guess that CPanel uses "virtual" URLs (i.e. not pointing to Actual Files), and thus URLs like /cpanel/some-action-that-is-not-actually-a-file are getting caught by the first rule rather than the later ones.

Try moving the last two rules between RewriteEngine and your first RewriteCond ?

(EDIT: And also fix the redirect loop as noted in comments under the question)

share|improve this answer
    
Thanks just done as you said when I visit anything under /cpanel or /login I get "The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete." the rest of the site works fine any ideas? –  Shutupsquare Oct 28 '12 at 19:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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