Background

I migrated my wordpress blog posts from wordpress to jekyll hosted on github successfully. This was a lot of manual work. I decided to use a subdomain for my jekyll site, but the wordpress site was hosted on the main domain www.feutl.com. I needed to figure out a way to redirect any permalink from wordpress www.feutl.com/blogposttitel/ to blog.feutl.com/blogposttitle/

Jekyll was already aware of those permalinks used by wordpress, this was not an issue any more, but getting the .htaccessfile redirect the requests correctly was tricky, especially because feutl.com and www.feutl.com should not be redirect.

Searching the web for a solution was like searching for the needle in tha haystack. I tested some given solutions by others and came to the conclusion it is much easier to read the manual for mod_rewrite and tutorial sites myself and understand what it does.

But the real live saver was the online .htaccess rewrite rules tester

Problem

This are some of the URLs which needed to be rewritten

url rewrite
www.feutl.com www.feutl.com
feutl.com feutl.com
www.feutl.com/ www.feutl.com/
www.feutl.com/permalink/ blog.feutl.com/permalink/
www.feutl.com/permalink www.feutl.com/permalink
www.feutl.com/blog/ blog.feutl.com

Solution

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/blog/$
    RewriteRule ^(.*)$ http://blog.feutl.com [L,R=301,NC]

    RewriteCond %{HTTP_HOST} ^www\.feutl\.com$
    RewriteCond %{REQUEST_URI} ^/(.*)/$
    RewriteRule ^(.*)$ http://blog.feutl.com/$1 [L,R=301,NC]
</IfModule>

.htaccess rewrite rules tester