Zine

open source content publishing system


Recipes

Apache RedirectMatch

If you used to run WordPress and imported your old blog into Zine you now need to make sure your old URLs are still available, yet, redirected to the new ones.

If you served your old blog like:

http://blog.domain.tld/index.php/2008/01/01/my-blog-post/

The new URL will be:

http://blog.domain.tld/2008/01/01/my-blog-post

If you run apache you can make use of RedirectMatch to redirect your old URL's to the new ones.

Add to your vhost configuration the following lines:

RedirectMatch permanent ^/index.php(.*)([/]+)$ $1
RedirectMatch permanent ^/index.php(.*)$ $1

The first rule, will permanently redirect the URL's that contain the last / in the url, the second will permanently redirect those that do not contain the last /. I was unable to make that in a single rule, the redirects didn't seemed to work.

The last thing is to redirect the old uploads path to the new one:

RedirectMatch permanent ^/wp-content/uploads/(.*)/(.*)/(.*)$ /_uploads/$3

This will redirect:

http://domain.tld/wp-content/uploads/2007/05/example.uploaded.picture.png

to:

http://domain.tld/_uploads/example.uploaded.picture.png

Of course you'll have to re-upload your old blog uploads to the new one and keep the same names.

Dynamic subdomains

Here's a VirtualHost setup to use dynamic subdomains. Each subdomain uses its correspondent instance folder. For this setup, I disabled Zine's websetup, or any requested subdomain would potentially start a new instance setup - and I want to set them manually.

<VirtualHost *:80>
    ServerName www.domain.com
    ServerAlias *.domain.com
    ServerAdmin webmaster@domain.com

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^([a-z0-9_-]+)\.domain\.com$ [NC]
    RewriteRule .* - [E=zine.instance_folder:/var/www/domain.com/instances/%1]

    WSGIScriptAlias / /path/to/zine/zine.wsgi
    <Directory "/path/to/zine">
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog /var/log/apache2/domain.com-error_log
</VirtualHost>