Apr 8, 2011
Simple htaccess tester
Last wednesday we where struggling with some complex rewrite rules. To test them we had to setup a local server and keep hitting that refresh button after each change. The only thing we could see is if the url was rewritten to the right location or not, but there was no way to actually see what’s happening. So we went on a hunt for a htaccess tester, something like Rubular which we use for regular expressions.
To our surprise there was no simple app to test rewrite rules, so we decided to dedicate our wednesday afternoon to build one, here is the result: htaccess.madewithlove.be.
It’s very easy to use, just fill in your htaccess and the url (starting with http://) you want to test and hit the “Check now” button.
By doing that your url will be rewritten according to your rewrite rules, the output view gives the new url and some debugging information you can use to improve your rules.
There are a couple of things which are not supported yet (like ${HTTP_REFERER} and %{REQUEST_FILENAME}) but we hope to add them in the future. Adding the ${HTTP_REFERER} will be quite easy but we need to find a good way to implement things like %{REQUEST_FILENAME}, please comment if you have suggestions on how we should do it.
That’s it! I hope you like it. Feel free to get in touch with us if any problems arise or if you have ideas on how we can improve it.
Update: We updated the checker to also support the HTTP_REFERER, HTTPS and SERVER_PORT variables, read more about the update in this blog post.




It doesn’t really work for me..
Seems like it’s my bad, thought you didn’t have to fill in the .htaccess part but obviously you do.
Nice work!
Nit: it’s really a
RewriteRuletester rather than a.htaccesstester.Actually, there are, e.g. http://martinmelin.se/rewrite-rule-tester/
Also, I should warn you guys – you’re using the HTML5
placeholderattribute on that page!!1!!omg As you know, HTML5 is dangerous and kills kittens and you shouldn’t be using it for the next twenty years or so.Hi there,
I like where you’re heading with this. I was wishing for something like this last week when doing a lot of complex rewrite rules. Unfortunately one of the things I needed was tests like this:
RewriteCond %{REQUEST_FILENAME} !-f
The only way I can see you getting this working on your website is have the user enter in the root path of the website and whether the url they are testing points to a physical file. That would solve some, but not all of the problems.
Other than that, a full ‘ls’ of the website dumped in there would at least let you check file locations etc. Not very user friendly I’m afraid though.
Good work anyway, I’ll be using this again.
Hey thanks for the great tool.
I found multiple RewriteCond (if-else like ones) are not working. I have to test each RewriteCond separately, nonetheless this is still a great tool.
e.g.:
# Skip the following four rules if the requested hostname is NOT example1.com or http://www.example1.com
RewriteCond %{HTTP_HOST} !^(www.)?example1.com$ [NC]
RewriteRule ^ – [S=1]
# Rules for example1.com or http://www.example1.com
RewriteRule ^/?$ “http://www.something.com/page.html” [R=301,L]
# Skip the following five rules if the requested hostname is NOT example2.com or http://www.example2.com
RewriteCond %{HTTP_HOST} !^(www.)?example2.com [NC]
RewriteRule ^ – [S=1]
# Rules for example2.com or http://www.example2.com
RewriteRule ^/?$ “http://www.somethingelse.com/somewhere/somepage.html” [R=301,L]
Sorry there were errors in my comments in the cond/rules above.
Instead of skip four/five rules, they should be skip a rule respectively.
For the %{REQUEST_FILENAME} which is normally used for either type detection, is it html or an image etc.. which im sure you are ok doing. however why not give the user an option to say (simple tick box) if the file exists or not?
Hi guys,
Great work on the rewrite tester!
One point – the output URL includes the url path, even if you haven’t specified it in the RewriteRule.
Even so, I love it! Great for some quick visual debugging – so well done!
Hi John, thanks for your feedback! We always include the full url because that makes it easier for most people. Especially when rewriting to different urls this can be extremely useful.
[...] things we changed since the initial launch of the [...]
Nice job guys! This tool just rescued me after struggling with a particularly annoying redirect issue.
Just a heads up that your tool strips out the escape backslash characters ‘\’. This doesn’t prevent your tool from working correctly but it does mean the finished code is no longer valid for an htaccess file without adding the backslashes back in.
Cheers!
Multiple people have reported this issue and we are going to try to solve it next week. Thanks for your feedback!
Do you support hashtags(#) and exclamation marks (!) supported?
RewriteRule ^[#|!|a]+/(.*)$ index.php?p=$1 [L]
Doesn’t work with # or !, but ‘a’ works…
I’ve almost tried all the possibilities
Hi Nathan, we might have missed something there. I will look into this when I find the time to do so.
RewriteRule ^(refer|referrer)([^/]*)?/?$ recommend.php?%{QUERY_STRING} [L]
{QUERY_STRING} is always empty, and I was wondering if you implemented it
It is implemented and it should work correctly. We will try to find time to debug it some more.
Hiya,
This is an awesome bit of kit, just used it to test a RewriteRule and it works and I have implimented the working code.
Thanks so much, I really appreciate the effort you have put into producing this
Very cool.
Another missing feature: “%N” back-references to the last matched RewriteCond. We have a site that redirects from an old domain to a new domain, but keeping the subdomain intact. E.g.
“http://bar.old.com/foo” redirects to “http://bar.new.com/foo”, and
“http://xyz.old.com/pdq” redirects to “http://xyz.new.com/pdq”
Our .htaccess, which works in real life but not in your tester:
RewriteCond %{HTTP_HOST} ^(.+)\.old\.com [NC]
RewriteRule (.*) http://%1.new.com/$1 [R,L]
Hi Glen, thanks for the feedback. We made some changes to implement this feature, can you check if it works now?
Wonderful stuff. Thanks for much for providing this.
µ
Just to add, my htaccess file is 2600 lines long (don’t ask) so this tool makes a huge difference.
(Even better if the report had an option to hide lines that didn’t trigger.)
µ
Love the tool, works great for testing and debugging rules!
Found a minor issue with the output url.
Input url: http://www.example.com/test?test=25
.htaccess:
RewriteCond %{QUERY_STRING} ^test=25$
RewriteRule ^test$ http://www.example.com/test123? [R=301,L]
Output url: http://www.example.com/test123?test=25
On an actual server, output url is: http://www.example.com/test123
The ? at the end strips off the querystring.
Again, thank you for this great tool!!
This issue is solved now.
Great tool – saved me a lot of time!
Thanks!!
Hi! I think this sentence is not working:
Redirect 301 /corporativa http://www.example.com/corp
Is there any option?
Thanks!
These are indeed not supported. We only support RewriteRule and RewriteCond at the moment.
I’d love to be able to indicate a directory or file structure so that I could test mod_rewrite directives more realistically.
Any suggestions on how that would work UI wise?
It would be great to URL decode to input before running the matching rules. I was testing a URL patter than contained %20 but had to change it to a space before it could be matched with \s in the rule.
Thanks!
Can you send us your test string an rewrite rules so we can verify?
We now url decode the input url, thanks for your feedback!
Hi, its a very good tool. I think it have a problem is about %{SERVER_ADDR}
I write that:
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1&srv=%{SERVER_NAME} [L,R=301]
but not show an IP address
Because we won’t know the IP-address of your server we can not show it. Feel free to suggest how we should implement it.
Hi, I sent you a tweet (@w3development) a few weeks back regarding a potential bug in your HTACCESS tester: an escaped space in the RewriteRule substitution is not picked up and the space is consequently seen as a delimiter in the RewriteRule. Here’s an example:
URL:
http://www.example.com/myfile.html
HTACCESS:
RewriteRule ^myfile.html /my\ file.html [R,L]
DESIRED OUTPUT:
http://www.example.com/my file.html
ACTUAL OUTPUT IN TESTER:
http://www.example.com/my\
Thanks for the feedback. This issue is resolved!
Thanks for the speedy response to the previous query! There’s another potential bug I spotted (sorry, should have mentioned this before!)… If the substitution string is delimited by quotes (single or double) then the quotes are seen as part of the substitution, rather than simply string delimiters. For example:
URL:
http://www.example.com/myfile.html
HTACCESS:
RewriteRule ^myfile.html “/otherfile.html” [R,L]
DESIRED OUTPUT:
http://www.example.com/otherfile.html
ACTUAL OUTPUT IN TESTER:
http://www.example.com/“/otherfile.html”
Great tool btw, thanks!
This is also solved now. Enjoy!
I like what you’re doing with this tool and it is definitely needed.
I had a problem because I’m trying to use rewrite conditions for security protection and then test them. I used RewriteRule .* – [F] with a RewriteCond %{QUERY_STRING}
My condition matched as it should have but I was told that the output from the htaccess would be the same URL as I put in. This is confusing because on a real server, the end result is a 403 forbidden message and further rule processing is stopped.
Also, I copied in my htaccess with lots of #comment lines and tabbed/indented rules. In the debugging window I kept getting your description about if a rule was matched or not against my #comments and the actual ReWriteCond line was missing altogether. Maybe you should automatically strip out any lines starting with # before displaying in the debugging.
RewriteRule .* – [F]is not supported in the current version of the htaccess tester.