Welcome Guest, Not a member yet? Register   Sign In
Can CodeIgniter change .htaccess all by itself?
#1

[eluser]php_princess[/eluser]
My webhost lets us use PHP 5.2, 5.3, or 5.4. The choice is ours. We change the version of PHP through PHP Config in cPanel but what that does is update our .htaccess file in the root of public_html. Well, my PHP version mysteriously keeps getting set back to the default of 5.2, and I have to manually go and set it back to 5.4. My host is scratching their head as to why. They're asking me if I have any scripts that could be altering that .htaccess file.

This is my .htaccess at the moment:
Quote:# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php
RewriteEngine on

#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-l

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

Right now my PHP version is 5.4, which is what it should be, and so far it's staying that way. The other day it had changed, once again, to 5.2 and I wish I'd known, then, to look in .htaccess because maybe I could see what happened. Maybe a script is deleting these two lines:
Quote:# Use PHP5.4 as default
AddHandler application/x-httpd-php54 .php

But I didn't look, so I don't know.

Thing is, I don't know any script of mine that would mess with .htaccess. Could CodeIgniter be the culprit?
#2

[eluser]CroNiX[/eluser]
No, by default CI doesn't alter any file on the filesystem. Your app could have code in it to do it though. I alter my .htaccess with my app by adding/removing deny ips for people who get blacklisted.
#3

[eluser]php_princess[/eluser]
By app code do you mean addons that I downloaded? I haven't added anything to CI. I just have my "scripts" (if you even call them that). I've made controllers, models, a couple helpers, and extended the form validator. I haven't written any code that alters .htaccess.

I guess tell my host that, no, I don't have any .htaccess changing code.
#4

[eluser]PhilTem[/eluser]
If you wrote all of your app's code by yourself and have never written anything that changes the .htaccess-file deliberately, then you won't be changing it.
Futhermore, I really don't think that your host service changes a .htaccess file in your public_html. That would be a little weird, but maybe they do it that way. To me it would be more reasonable to have another file but .htaccess changed by your setting in the cPanel.
Assuming above mentioned thoughts, I guess, that someone else is changing content of your .htaccess file. Does anybody else have access to your server?

Maybe you want to try changing the permissions on .htaccess to 600 and see what happens (as long as you are able to and the owner is you but not the user that your host's webserver runs with)
#5

[eluser]php_princess[/eluser]
[quote author="PhilTem" date="1347486481"]Does anybody else have access to your server?[/quote]
Nope.

[quote author="PhilTem" date="1347486481"]Maybe you want to try changing the permissions on .htaccess to 600 and see what happens (as long as you are able to and the owner is you but not the user that your host's webserver runs with)[/quote]

I shall try this.

Edit: Permissions were at 644, I changed them to 600 and got this error when I tried to go to one of my pages:
Quote:Forbidden

You don't have permission to access /auth/signup on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Apache Server at www.mydomainnamehere.com Port 80
#6

[eluser]CroNiX[/eluser]
Are you sure you aren't reuploading an old htaccess when pushing changes to the server?
#7

[eluser]php_princess[/eluser]
Hmm, I don't think so. I only upload one file at a time and its never .htaccess unless I just edited it and thus want it changed, but I haven't done that in awhile.
#8

[eluser]CroNiX[/eluser]
Not sure what else to suggest. Things don't just change themselves, and if you or your app isn't doing it...

One thing that's also strange about the htaccess you first posted is this line is commented out:
#RewriteCond %{REQUEST_FILENAME} !-d
and it shouldn't be

You can also get rid of this:
RewriteCond $1 !^(index\.php|images|robots\.txt)
#9

[eluser]php_princess[/eluser]
Well, I'm not even 100% sure it's .htaccess that's causing my problem. That's an idea my host came up with for what could be the cause of my problem. I have no idea how cPanel works and it could be a malfunction somewhere in that. It could even be cPanel changing the .htaccess. Or maybe it is changing some configuration file that it uses to determine PHP version. I just don't know.

Note: I originally didn't have any rewrite conditions commented out and it caused some problem which I have long since forgotten what it was. Since all I cared about at the time was getting CodeIgniter to work, I fixed the problem in the quickest way I could which was to comment out the problem-causing rewrite conditions and tell myself I'd come back later and decide what I was gonna keep in .htaccess, and what I was gonna erase. Then I forgot all about it, lol

But yeah, since I'm not using the commented out rewrite rules I guess I can just delete them.

#10

[eluser]CroNiX[/eluser]
Your problem was probably because of the line I said you should remove conflicting with the other lines.

This is a good htaccess for CI
Code:
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

Yes, some control panels can/will alter htaccess, and add lines like "AddHandler application/x-httpd-php54 .php" to switch the php version that you are using on the server, since you can actually have different versions of PHP running on the same server. You might need that at the top of you htaccess, but the rest should probably be what I posted unless you understand the implications.




Theme © iAndrew 2016 - Forum software by © MyBB