{"id":46,"date":"2013-02-06T14:22:59","date_gmt":"2013-02-06T13:22:59","guid":{"rendered":"http:\/\/techblog.vindvejr.dk\/?p=46"},"modified":"2013-02-06T15:11:29","modified_gmt":"2013-02-06T14:11:29","slug":"46","status":"publish","type":"post","link":"https:\/\/techblog.vindvejr.dk\/?p=46","title":{"rendered":"Permanent redirection to default host in Apache"},"content":{"rendered":"<p>A few weeks ago at work, I needed to rename a webhost. To avoid breaking a lot of links to the old hostname, I set up permanent redirection, but ran into an infinite loop. I tried both a simple Redirect statement like this:<\/p>\n<p><code>Redirect permanent \/ http:\/\/newhost\/<br \/>\n<\/code><\/p>\n<p>And the same thing using mod_rewrite. I have done this many times before at home, but what was special about this case is that the web server was set up as default host. So I just added a virtual host with the old hostname. Eventually I got it to work with mod_rewrite by using a RewriteCond statement to break the loop:<\/p>\n<p><code>&lt;VirtualHost *:80&gt;<br \/>\n    ServerName oldhost<\/p>\n<p>    &lt;IfModule rewrite_module&gt;<br \/>\n        RewriteEngine on<br \/>\n        <strong>RewriteCond %{HTTP_HOST} oldhost<\/strong><br \/>\n        RewriteRule ^\/(.*)$ http:\/\/newhost\/$1 [R=permanent,L]<br \/>\n    &lt;\/IfModule&gt;<br \/>\n&lt;\/VirtualHost&gt;<br \/>\n<\/code><\/p>\n<p>However, I&#8217;m still not sure why this is neccesarry, since the first rewritten URL should end at the default host which doesn&#8217;t rewrite anything.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few weeks ago at work, I needed to rename a webhost. To avoid breaking a lot of links to the old hostname, I set up permanent redirection, but ran into an infinite loop. I tried both a simple Redirect &hellip; <a href=\"https:\/\/techblog.vindvejr.dk\/?p=46\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=46"}],"version-history":[{"count":9,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions"}],"predecessor-version":[{"id":55,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=\/wp\/v2\/posts\/46\/revisions\/55"}],"wp:attachment":[{"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techblog.vindvejr.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}