Some htaccess files

Make .php files accessible as .htm(l)

RewriteEngine On
RewriteRule ^(.*)\.html?$ /$1.php [L]

Rewrite 123 into /foo.php?file=123 with a permanent redirect

RewriteEngine On
RewriteRule ^([0-9]+)$ /bla.php?file=$1 [L,R=301]

Can't remember what it does ;o)

RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*/[^.]+)$
RewriteRule ^.*/[^.]+$ %1.php [L]

Force all HTTP-Requests to be redirected to HTTPS

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Run things through a parser

In this special case, I have a directory /efun/ in which some .xml files reside. I want them to be able to be called as but be treated like someone typed

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/xmlparse.php
RewriteRule .* /xmlparse.php/efun%{REQUEST_URI} [L]

Simulate mod_gzip

Sometimes, mod_gzip is not available. If you have lots of .html files, just make .gz equivalents and install this .htaccess, it will then chose the .gz one (if available) and send it back. You could also add a check to call a script if the .gz version does not exist, or even compare modification-times and compress on-demand...

RewriteEngine On
RewriteCond %{HTTP:Accept-Encoding} .*gzip.*
RewriteCond %{SCRIPT_FILENAME}.gz -f
AddEncoding x-gzip htm.gz
AddEncoding x-gzip html.gz
RewriteRule (.*\.html?$) /$1.gz [L]

Authentificate and then redirect based on the username

AuthType basic
AuthUserFile /www/foo/bar/.htpasswd
AuthName Blah
require valid-user

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /foo/bar/%{REMOTE_USER} [L]

URL-hiding in perfection

RewriteEngine On
RewriteRule .*{REQUEST_URI} [L,P]

What all stupid customers want

I don't know why, but everyone who has articles seems to have the tendency to divide them into themes and articles. But they want them to be accessible like: 123,678.html

RewriteEngine On
RewriteRule ^([0-9]+),([0-9]+).html$ /app.php?vars[article]=$1&vars[theme]=$2 [L]

Providing a subdomain service

Stupid customers want stupid things: subdomain services :-/ Unfortunately, they all want to use MySQL (because they are customers and customers are stupid!). Here's the most elegant solution, using a RewriteMap. Unfortunately it doesn't work with all providers, but it uses proxying, so you could also use it to "hide" your dyndns server behind a nice subdomain... To create the test.db file, you should be a bit familiar with the format and then write a converter. Duuh, it's so simple *sigh*

RewriteEngine On
RewriteMap test dbm:test.db
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.tld$
RewriteRule .* ${lb:%1}%{REQUEST_URI} [P,L]

Last modified: 26.07.2006 [01:26:48]