Posts Tagged ‘.htaccess’

Apache versions and .htaccess files

The other day I was looking into a problem someone was reporting with an Apache RewriteRule, only to conclude that it was using features of the Regex library which weren’t available in their version of Apache.

I found a means of detecting the different versions of Apache using the mod_version module. This allows you to write htaccess files which can fall back to other rules for older versions of Apache.

Unfortunately it’s only been available since version 2.0.56, but given that this was before the first release of version 2 it’s fairly safe to assume that anything without mod_version will be running Apache 1.

I will concede that this sounds very obvious, but there was a surprising lack of results in google for any of the keywords that I thought to try. For the benefit of anyone searching for this; below is an example of how you can use mod_version in practice:

<IfModule !mod_version.c>
	# Earlier than version 2.0.56, so almost certainly 1.x
	# as 2.0.63 was the first release of version 2.
</IfModule>
<IfModule mod_version.c>
	# Version 2.0.56 or later
	<IfVersion < 2.2>
		# Before version 2.2
	</IfVersion>
	<IfVersion >= 2.2>
		# Version 2.2 or later
	</IfVersion>
</IfModule>
Posted: June 3rd, 2010
Categories: Programming, World Wide Web
Tags: , ,
Comments: No Comments.