I was wondering how to create and debug this kind of script that can become a bit of headache if you are not used to write them (like me).
Do you use tool to create them?
Any tips to debug what's going on instead of just create a local structure and see what's happening in the browser?
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.
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.
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/.
The <IfModule mod_rewrite. c>... </IfModule> block ensures that everything contained within that block is taken only into account if the mod_rewrite module is loaded. Otherwise you will either face a server error or all requests for URL rewriting will be ignored.
Note to readers: the old answer doesn't work anymore.
As of version 2.4, Apache no longer allows the RewriteLogLevel
and RewriteLog
directives. Now they're all bundled with the single LogLevel
directive (see Log Files documentation), which supports module-specific log levels with prefixes and trace[1-8]
constants. To set the highest level of logging specifically for the rewrite module, you now use the following:
LogLevel warn rewrite:trace8
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With