Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popular techniques to debug .htaccess

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?

like image 946
John Avatar asked Mar 21 '09 12:03

John


People also ask

How do I debug .htaccess file?

To test your htaccess rewrite rules, simply fill in the url that you're applying the rules to, place the contents of your htaccess on the larger input area and press "Check Now" button. Thanks for the pointer to this tool, which I found the most direct way to debug my problem.

How do you check my htaccess file is working or not?

Save the file and type the URL yoursite.com/foobar/ . If the reditect works and the URL gets redireted to the homepage of example.com then it's clear that your htaccess is working and being read by your Apache server. If it still doesn't work then the problem might be that your hosting provider has not enabled it.

What is Rewriteengine on htaccess?

htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.

Why is my .htaccess file not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.


1 Answers

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

like image 194
Alekc Avatar answered Oct 15 '22 15:10

Alekc