.htaccess file generator
From web form to .htaccess…
.htaccess files are apache files which you can modify to make your web site to some crazy things. You can:
- Redirect to another url
- Set default files (index.html) if the user just specifies a directory
- Protect certain files
- Password-protect directories
- Specify mod_rewrite rules (a black art) as I do below
- map files and folders
- Specify 404 error and other pages
- etc.
I create and modify .htaccess files a lot but am acutely aware that they can do a lot more than I’ve been using them for.
Enter the .htaccess Generator! What’s going to be great about this site, for me, is that I can experiment with the features and see what the exact right syntax looks like.
For instance, how do I redirect the standard stylesheet to one appropriate for mobile phones? I filled out the form as follows:
I then got this back:
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} [NC]
RewriteRule ^test\.css$ [L]RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[345].*Gecko*
RewriteRule ^test\.css$ firefox.css [L]RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[345].*MSIE*
RewriteRule ^test\.css$ ie.css [L]RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12].* [OR]
RewriteCond %{HTTP_USER_AGENT} ^Lynx/*
RewriteRule ^test\.css$ lynx.css [L]RewriteRule ^test\.css$ other.css [L]
Now, I suspsect that my mobile phone might give me back something more specific, which I could type in here but now that I know the pattern I think I can take it from here.
Neat stuff.