Apache Redirect Exception

Tonight I had to define an exception to my Apache redirect rules. Since the “planet” rss-aggregator of my university doesn’t support SSL connections to fetch its feeds, I made an exception so that my RSS feed is also available via HTTP. However if you explicitly use the HTTPS protocol it should be available via SSL too.

This is the resulting apache virtual-host config:

<VirtualHost *:80>
    ServerName tim-kraemer.de
    [...]
    RedirectMatch permanent ^/(?!uni.rss$).* https://tim-kraemer.de/
    DocumentRoot /home/tim/www/
    <Directory />
        Require all granted
        [...]
    </Directory>
</VirtualHost>

The RedirectMatch permanent clause sends an HTTP 301 header, to tell the client that the website is permanently redirected to the encrypted HTTPS version. ^/(?!uni.rss$).* is an regular-expression, which matches on everything (and therefore redirects every url) except the url-part ‘uni.rss’, which is one of the adresses of my RSS-feed.

Please share this article on twitter or via email and flattr it, thanks!