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?

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
John
  • 32,403
  • 80
  • 251
  • 422

1 Answers1

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

Alekc
  • 4,682
  • 6
  • 32
  • 35
  • 1
    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. – Nedko Jan 24 '12 at 12:22
  • So what are your options then? – thoni56 Jan 27 '12 at 11:09
  • @ThomasNilsson, Rob Russell has a suggestion for rerouting rewrites into 301 redirects, and sending debug info back to the console: http://www.latenightpc.com/blog/archives/2007/09/05/a-couple-ways-to-debug-mod_rewrite (I haven't tried it yet). – ericsoco Aug 16 '12 at 04:20
  • More here: http://stackoverflow.com/questions/9153262/tips-for-debugging-htaccess-rewrite-rules including a recommendation to *not* use 301s. – ericsoco Aug 16 '12 at 04:23
  • Note: RewriteLog is deprecated for Apache 2.4+. See https://wiki.apache.org/httpd/RewriteLog – bryanbraun Aug 01 '15 at 21:25