Specific .htaccess line causing error after server move

Hi there,

I’m overseeing a move from one server to another, and on the new server it appears that our .htaccess file is now throwing off 500 Internal Server Errors. I assume there’s some kind of difference in settings between the two which would explain it, but the host hasn’t pinpointed anything yet.

Naturally, I began commenting things out until I found out what was causing it. This line appears to be the culprit:

RewriteRule (.*) index.php [O]

Does anyone know why this might be? Are there any settings that might interfere with this rule, perhaps?

Does the new server have mod_rewrite enabled/installed in apache (I assume the new server is running apache? what version?)

Does the .htaccess also have the line

RewriteEngine on

?

Thanks for the reply.

Yup, it’s Apache, and it does have that line earlier in the file.

They do allow mod_rewrite, though they require that we use RewriteBase, because of the way their hosting environment works (for whatever reason).

what happens if your remove the [0] or is that [O]?

It’s a zero. Removing it removes the errors! Some of the rewrites are working and some aren’t, but this is a huge step forward! Many thanks.

I’m a luddite when it comes to rewrite rules; what did removing it do? :slight_smile:

TWTC,

I know of no flag that would/could use zero (or O, for that matter) so that’s one problem. The second problem is the one I rant about regularly: Using “lazy regex,” i.e., (.). Don’t you understand that (.) will match nothing or :kaioken:EVERYTHING :kaioken: INCLUDING index.php? Also, that mod_rewrite won’t quit until it cycles through your code WITHOUT a match?

To have a look at the tutorial in my signature. It’ll remove your “luddite” label and replace it with “guru.”

Regards,

DK

Whoa, ease up there, dk. :slight_smile: I didn’t write this thing, and luddite though I may be, I understand that the (.*) will match everything. I’m just a little more focused on getting this site up and running than making it more efficient at the moment. :slight_smile:

Anyway, thanks for the link, I’ll have a look.

Re: the zero. So, it’s a completely invalid command, then? That seems pretty odd…especially seeing as how it’s working fine on our other server! That seems awfully strange; anyone have any idea what the deal is?

TWTC,

(.*) should make your code LOOP until it fails. Nothing to do with optimizing code!

Correct. I have no idea where that could have come from but it should be causing 500 Errors.

Regards,

DK

Well, yikes, I don’t know what to tell you about looping, because whatever the reason, this line…

RewriteRule (.*) index.php [O]

…is running on a live site with no issues. I have no idea why, but I’ve triple-checked it, and it’s there and the site loads promptly.

By the by, we’re using Joomla along with ARTIO’s JoomSEF extension, and the part of the file with this line in it is headed with “Begin - Joomla! core SEF Section” and immediately followed by this line:

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

Does that shed any light on things?

Yes, it says that you’re not showing us the preceding RewriteCond which is preventing the loop. Without sufficient information, oh, what to do?!?

Regards,

DK

Hey now, no reason to keep getting excited. :slight_smile: This isn’t my code and, being a layman I don’t know what’s necessary unless told. I’ll be glad to post the code; here are the lines preceding the loop:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\\.php|\\.html|\\.htm|\\.feed|\\.pdf|\\.raw|/[^.]*)$  [NC]

TWTC,

Okay, those are WHY the RewriteRule isn’t loopy.

FYI:

!-f is not a file

!-d is not a directory

!^/index.php (poor regex and won’t work on Apache 2.x) duplicates the not file but would prevent looping on index.php (properly formatted)

(/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$ is a list of things to ignore which includes everything without a dot character which follows a /

Regards,

DK

Sorry for the delay in my response. Thanks very much for the explanation. I’ll certainly be having a look at the article in your signature.