tags/ploneNico Schotteliushttps://www.nico.schottelius.org//tags/plone/Nico Schotteliusikiwiki2016-02-25T13:34:32ZMixing redirects and rewrites with lighttpd and Plonehttps://www.nico.schottelius.org//blog/lighttpd-plone-rewrite-redirect/2016-02-25T13:34:32Z2015-02-03T14:47:26Z
<h2>The situation</h2>
<p>As you may already know,
<a href="https://www.nico.schottelius.org//blog/restart-to-write-news/">I am</a>
<a href="https://www.nico.schottelius.org//blog/migration-1-configs/">migrating</a>
<a href="https://www.nico.schottelius.org//blog/migration-2-freebsd-raid-monitoring-foss/">many of</a>
<a href="https://www.nico.schottelius.org//blog/migration-3-ccollect/">my websites</a> into this one.</p>
<p>Today I also began to redirect stuff from my
previous personal website, http://nico.schottelius.org.
I am (still) running <a href="http://www.plone.org">Plone</a> on that
site, behind <a href="http://www.lighttpd.net/">lighttpd</a>. The
configuration of lighttpd looks like this:</p>
<pre><code>$HTTP["host"] =~ "^(nico|nico2)\.schottelius\.org$" {
url.rewrite-once = ( "^/(.*)" => "/VirtualHostBase/http/nico.schottelius.org/cms/VirtualHostRoot/$1" )
var.logdir = "/home/server/www/nico/nico.schottelius.org/logs/"
accesslog.filename = logdir + "access.log"
proxy.server = ( "" => (
( "host" => "192.168.6.2", "port" => 8082 ),
( "host" => "192.168.6.2", "port" => 8083 )
))
}
</code></pre>
<p>(<a href="https://www.nico.schottelius.org//configs/lighttpd-zope-http-and-https">a more detailled version can be found here</a>)</p>
<h2>The idea</h2>
<p>Now I created a new <a href="https://www.nico.schottelius.org//about/">about page here</a> and want to redirect
the old URLs <strong>"^/ueber/nico-schottelius$"</strong> and <strong>"^/about/nico-schottelius$"</strong>
from the Plone site to it.</p>
<p>First I tried the normal redirect like this:</p>
<pre><code> url.redirect = ( "^/ueber/nico-schottelius$" => "http://www.nico.schottelius.org/about/",
"^/about/nico-schottelius$" => "http://www.nico.schottelius.org/about/" )
</code></pre>
<h2>The solution</h2>
<p>Unfortunately, this did not work. You may already have spotted the bug...
The correct way to redirect pages from lighttpd in front of
<a href="http://www.zope.org">Zope</a>, which does <strong><em>rewriting</em></strong> is to match on the
<strong>rewritten</strong> path! Thus, the following code does the
<a href="http://nico.schottelius.org/about/nico-schottelius">correct redirect</a>:</p>
<pre><code>url.redirect = (
"^/VirtualHostBase/http/nico.schottelius.org/cms/VirtualHostRoot/ueber/nico-schottelius$"
=> "http://www.nico.schottelius.org/about/",
"^/VirtualHostBase/http/nico.schottelius.org/cms/VirtualHostRoot/about/nico-schottelius$"
=> "http://www.nico.schottelius.org/about/"
)
</code></pre>
<p>You can use <a href="http://curl.haxx.se">curl</a> to verify the redirect:</p>
<pre><code>[22:54] ikn% curl -i http://nico.schottelius.org/about/nico-schottelius
HTTP/1.1 301 Moved Permanently
Location: http://www.nico.schottelius.org/about/
Content-Length: 0
Date: Mon, 22 Jun 2009 21:01:39 GMT
Server: lighttpd/1.4.19
</code></pre>