Popular techniques to debug .htaccess
Asked Answered
H

2

20

I'm a self-taught coder and I like to debug by echoing suspicious variables and commenting out code.

Lately, I've had to learn more about the .htaccess file. I need it to do things like interpret php scripts as php5, url rewriting, limit file upload size etc.... I have a lot of trouble debugging a .htaccess file. I often have to migrate PHP applications from one shared hosting environment to another. Sometimes this breaks the .htaccess file (or instead, something in the .htaccess file breaks the site). I check to make sure domain names are updated.

Are there popular techniques for debugging a .htaccess file? Is it just look in the apache logs? Anything else?

Huckleberry answered 21/3, 2009 at 12:3 Comment(1)
stackoverflow.com/a/21605970Sinuation
C
11

Looking in the apache logs is the easiest way to debug .htaccess imho (adding rewriteLog Directive if necessary)

About migrating: if you are not using any physical file paths inside .htaccess (i.e. /var/www/site/script.php) they should be working without problems. If this is not the case, first try to remove all options and leave only redirect directives, in this mode you can see if it's problem with server configuration which denies rewriting of default settings.

Some reference

Compte answered 21/3, 2009 at 12:9 Comment(5)
It is good to know than "RewriteLog" does not work on shared hosting because it has to be turned on in the httpd.conf which is not accessible in this case.Bronwynbronx
So what are your options then?Indent
@ThomasNilsson, Rob Russell has a suggestion for rerouting rewrites into 301 redirects, and sending debug info back to the console: latenightpc.com/blog/archives/2007/09/05/… (I haven't tried it yet).Truck
More here: #9153762 including a recommendation to not use 301s.Truck
Note: RewriteLog is deprecated for Apache 2.4+. See wiki.apache.org/httpd/RewriteLogTimoshenko
S
0

There's an online tester or syntax or rule interpretor checking tool called: htaccess tester at htaccess.madewithlove.be

Sinuation answered 3/4 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.