.htaccess errors, how to know what to fix?

Hi all,

I’ve run my .htaccess access file’s content through the Lyxx htaccess checker because I’m having a bad time fixing Apache always giving me a 500 server error.

The Lyxx checker can be found at: http://www.lyxx.com/freestuff/002.html

If I just leave the 301 redirects in my htaccess file the website will load okay. Lyxx has identified the following lines (marked in red) causing the 500 server error:

line 1:
<IfModule mod_deflate.c>
line 2: (1)
a2enmod deflate
line 3: (1)
SetOutputFilter DEFLATE
line 4: (1)
AddOutputFilterByType DEFLATE text/plain
line 5: (1)
AddOutputFilterByType DEFLATE text/html
line 6: (1)
DeflateCompressionLevel 9

line 7:
BrowserMatch ^Mozilla/4 gzip-only-text/html
line 13:
RewriteEngine On
line 14: (152)
RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6
line 15: (151)
RewriteRule ^(.+)\.phtml$ index.php?$1

line 16:
line 17:

Deny stealing content (no hot linking)

line 18: (20)
RewriteCond %{REQUEST_FILENAME} .*jpg$|.*jpeg$|.*gif$|.*png$|.*ico$|.*js$|.*css$|.*txt$ [NC]

line 19:
RewriteCond %{HTTP_REFERER} !^$
line 79:
RewriteCond %{REQUEST_FILENAME} !-d
line 80: (151)
RewriteRule (.php) /error/404.php

line 81:
line 191:

I have banned them by User-Agent and IP address.

line 192: (51)
RewriteCond %{REMOTE_ADDR} ^12\.148\.196\.(12[8-9]¦1[3-9][0-9]¦2[0-4][0-9]¦25[0-5])$ [OR]
line 193: (51)
RewriteCond %{REMOTE_ADDR} ^12\.148\.209\.(19[2-9]¦2[0-4][0-9]¦25[0-5])$ [OR]

line 194:
RewriteCond %{HTTP_USER_AGENT} NPBot[NC]

I understand the numbers in brackets () indicate the type of errors. So far I can’t locate what these numbers mean, and as a result I can’t figure out what syntax needs to be changed/added.

Anyone here know exactly what’s going wrong?

Many thanks,

nsm,

Hmmm, thanks for that feedback. It’s obviously a little disconcerting but something useful to know.

Regards,

DK

nsm,

A 500 error is generally caused by a syntax error. Looking at your CODE:

WHERE is the </IfModule>?

RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6

I doubt that all the commas are acceptable in the query string.
Is .phtml an acceptable Type on your server?
Where is the Last flag?

RewriteRule ^(.+)\.phtml$ index.php?$1

Same as above without the dot characters or specifying digits (NO Last flag so this is ANDed with the prior RewriteRule

RewriteCond %{REQUEST_FILENAME} .*jpg$|.*jpeg$|.*gif$|.*png$|.*ico$|.*js$|.*css$|.*txt$ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.php) /error/404.php

No Last flag (also ANDed with both prior RewriteRules.
Mutually exclusive so this can NEVER redirect (extensions).

I have banned them by User-Agent and IP address.

RewriteCond %{REMOTE_ADDR} ^12\.148\.196\.(12[8-9]¦1[3-9][0-9]¦2[0-4][0-9]¦25[0-5])$ [OR]
RewriteCond %{REMOTE_ADDR} ^12\.148\.209\.(19[2-9]¦2[0-4][0-9]¦25[0-5])$ [OR]
RewriteCond %{HTTP_USER_AGENT} NPBot[NC]

No space before Flag is a syntax error.

Regards,

DK

dklynn,

Thanks for taking time out to respond.

I ended up going back to the previous version of my .htaccess file that was currently onlie and working with the previous version of the old site and mixing and matching new and old line by line/part by part until I could nail down the issue. Once I did that I could use the new htaccess thus its improvements over the old one.

Turns out I did an awful mistake of removing a lot of the [L] = last chars from the htaccess rule lines, which didn’t help - I put them back and fixed them up. There was also however an issue with an 301 redirect, however this only caused an error online, never on localhost. I wasn’t specifying the full http://www etc. redirect address for one of the 301’s. As soon as I fixed this the problem went away.

All in all this got me worried, fortunately I nailed down the problem areas and once I did it was downhill from there, step by step.

Thanks again.

Let’s put it down to how Apache is configured on the hosted server. If I could get it work without the http, I would but had to surrender on this occasion.

Thanks for your suggestions, I’ll keep them in mind for later.

As far as the absolute redirection goes, even though this 301 in question was an internal redirect it didn’t want to work online without the http. I guess it’s how Apache was configured, like I say on localhost via Wamp’s setup of Apache it worked fine.

nsm,

No problem. Your PHP code won’t work without ; or } so think of mod_rewrite in the same terms to remember those Last flags.

As for the Redirect, all that’s required is an absolute redirection. While the external (http://yadda/yadda) is preferred, it can also be an internal redirection (/yadda).

Regards,

DK