3

I have a CodeIgniter project running on CentOS, with an EV cert successfully installed.

I don't want SSL used when the /rss directory is accessed. I had this working, but I broke it somehow during an upgrade.

Here is my .htaccess file, which I think is correct:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # redirect to SSL connection
    RewriteCond %{REQUEST_URI} !^/rss/
    RewriteCond %{SERVER_PORT} 80
#   R=301 sends HTTP Moved Permanently L=Last rule for this request
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule> 

Going to the site, the url is correctly changed to https://www.site.com But going to www.site.com/rss also gets changed to https. I don't want it to use ssl for that directory. I think the .htaccess file is correct, so maybe it is a CodeIgniter thing... IF anyone has an idea, I would be very grateful.

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
wclark
  • 436
  • 4
  • 14

1 Answers1

4

What might be happening is that a mod_dir is not intervening in the order that it did before (mod_dir by default will redirect, if you access a directory but don't include a trailing slash, to the same URL with the trailing slash). If you try to access http://www.site.com/rss RewriteCond %{REQUEST_URI} !^/rss/ matches (since the request uri starts with "/rss" != "/rss/") and it gets rewritten to https://www.site.com/rss. Then mod_dir takes over and redirects you to "https://www.site.com/rss/". It's possible that before the upgrade, mod_dir applied the redirect first so you get redirected to "http://www.site.com/rss/" then the first condition (!^/rss/) fails, thus you don't get rewritten to https://

Try changing the first rewrite condition to:

RewriteCond %{REQUEST_URI} !^/rss/?$

So URI's like "/rss" and "/rss/" will fail the match and not get redirected to https://

Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Thanks for the help. I tried your suggestion. It is probably necessary, but did not help. I am directed to https://www.mysite.com/?index.php/rss, instead of http://www.mysite.com/rss. – wclark Oct 27 '11 at 17:12
  • Ah, of course. Try adding `RewriteCond %{SERVER_PORT} 443` in front of each of the `RewriteRule ^(.*)$ /index.php?/$1 [L]` entries. – Jon Lin Oct 27 '11 at 17:48
  • No wait, why would it ge directed to "?index.php/" instead of "/index.php?" ? – Jon Lin Oct 27 '11 at 17:53
  • It feels like it is so close. I think CodeIgniter might be the problem now. Now it directs correctly to www.mysite.com/rss, but the browser says page not found. As far as the index.php/ deal, I notice when I hork the .htaccess file, sometimes I get urls like that. Oddly enough, they work! But part of the job of the htaccess file is to remove the index.php that CodeIgniter uses by default. – wclark Oct 27 '11 at 19:34
  • Got that wrong, entering www.mysite.com/rss get routed to https://www.mysite.com/index.php?/rss right now. – wclark Oct 27 '11 at 19:43
  • *Now it directs correctly to www.mysite.com/rss, but the browser says page not found.* I think this might be the crux of the problem. `/rss` should not be rewritten to `/index.php?/rss` unless /rss doesn't exist (the last set of RewriteCond). Are you sure /rss exists? – Jon Lin Oct 27 '11 at 19:59
  • this is a codeigniter project, so yes, the controller rss does exist. Check this doc, 2nd paragraph, [Removing the index.php file](http://codeigniter.com/user_guide/general/urls.html) – wclark Oct 28 '11 at 02:54
  • I'm not familiar with Codeigniter, but if apache's mod_rewrite doesn't think /rss exists, it'll fail the rewritecond tests for -f and -d – Jon Lin Oct 28 '11 at 03:02
  • The first rule is all I added to deal with ssl. The rest all works perfectly with the Codeigniter url strangeness, when everything is http or if everything is https. My problem is I want everything to be https except \rss. – wclark Oct 28 '11 at 04:03