Search code examples
regexapache.htaccessmod-rewrite

Better way to test .htaccess file


I don't have much experience with htaccess rules, some of them are working but when I add a new rule or remove one, how do I test them?? I cannot test it on the actual server. Even in my localhost, I won't be able to test some like https rules, www and other stuff.

I can test the rest of url patterns but when I add the www and https rules along with the tested ones on the live server, it gives an error and then I continue testing them on the live server.

Is there a way to test them without using the actual server and not create another server for testing those rules. Something like a htaccess rule checker or something!?


Solution

  • There are a few web based testers available to use, unfortunately, these don't always understand all the syntax to accurately check how it works on a real site.

    One web based one I like to use is this online tester from Made with Love; http://htaccess.madewithlove.be/

    It doesn't understand a few items such as %{REQUEST_FILENAME} but for general testing I think it should do the job for you. You copy your code into the box, and you can also submit a url to see what it will rewrite to. If you just want to check syntax errors there are a few web tools available as well.

    Using web based tools are great for an overall check, but you can't really be sure how it affects a real site until you upload it either to a dev version of the real thing.

    Just recently I've edited a htaccess file, which showed no syntax errors and worked as expected on the tester, which did not work at all on the real site. Site settings may have an impact and all other things which will not show on a web tool.