Though developing your application against localhost, development and production parameter environments can increase reliability and security, it often requires that requests be rewritten according to the target server’s setup. Adding rules to Apache’s htaccess configuration file and testing them on the fly works okay on localhost, but is less effective on development and a certified bad idea™ on production. Fortunately, there’s an easier way to test your htaccess rules before deployment.
The htaccess tester by madewithlove provides a straightforward frontend for inputting rewrite rules and testing them from an arbitrary request URL:
As an example, let’s say that we’re serving an application at
example.com/demo. Let’s further say that our application has a route,
example.com/demo/login, that users can access when they want to login. Whenever a user requests a route that our application is serving, we’d like to serve the response over HTTPS. This is especially true for logins and any requests made after logging in. A final concern is that while our development and production servers have TLS certificates, localhost does not.
Using the htaccess tester, it’s easy for us to write rules that target requests for our application’s production domain,
example.com, check for HTTPS and, if HTTPS is off and the request is accessing a route behind the
/demo path, rewrite and redirect the request to be served over HTTPS:
Without deploying our rules, we can now be certain they will match and rewrite the desired requests: all of the information we need appears in the ‘Debugging info’ portion of the tester.