<p>This plugin allows pages (and attachments) to specify alternative/old
URLs which should redirect to their current location.</p>
<blockquote>
<p>[!IMPORTANT]
Currently this plugin <em>will not work</em> on Lektor sites with <ahref="https://www.getlektor.com/docs/content/alts/"rel="nofollow">alternatives</a> enabled.</p>
</blockquote>
<h2>How it works</h2>
<p>The plugin looks for a field named (by default) <code>redirect_from</code> on pages
and attachments in the site. This field is expected to contain a sequence of URLs
to redirect from.</p>
<p>There are two ways that redirects may be implemented by this plugin.
Either or both may be enabled.</p>
<h3>Redirect pages</h3>
<p>Redirect pages can be generated at the specified URLs. The template for these
pages is up to you, however the intent is that these pages will attempt
an <em><ahref="https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh"rel="nofollow">meta refresh</a></em> and/or <em><ahref="https://developers.google.com/search/docs/crawling-indexing/301-redirects#jslocation"rel="nofollow">javascript redirect</a></em> to the target page.</p>
<h3>Redirect map</h3>
<p>A <em>redirect map</em> file can be generated. This may be used to configure your
web server to issue the desired redirects itself.
(Currently only an nginx-style map is supported.)</p>
<h2>Usage</h2>
<p>By default the plugin looks for a field named <code>redirect_from</code> on pages in the
site.
(The name of the field may be customized in the plugin configuration file. See below.)
This field should contain a sequence of URLs to redirect from — most
likely it should have a field type of <code>strings</code>.</p>
<p>E.g. To be able to generate redirects to your pages, you might add the
following <ahref="https://www.getlektor.com/docs/models/#fields"rel="nofollow">field</a> to your <code>models/page.ini</code> file:</p>
<spanclass="na">description</span><spanclass="w"></span><spanclass="o">=</span><spanclass="w"></span><spanclass="s">Other URLs which should redirect to this page</span>
<p>If a <code>template</code> is configured in the plugin configuration file (<code>configs/redirect.ini</code>),
<em>redirect pages</em> will be generated from the specified template. The intention is that
the resulting page will redirect the user to the target location using <ahref="https://developers.google.com/search/docs/crawling-indexing/301-redirects#metarefresh"rel="nofollow">meta refresh</a>
and/or a <ahref="https://developers.google.com/search/docs/crawling-indexing/301-redirects#jslocation"rel="nofollow">javascript redirect</a>.</p>
<p>Within the template, the target of the redirect is available as <code>this.target</code>.</p>
For the <code>url(external=true)</code> and <code>url(absolute=true)</code>
filters to work, a <code>[url][project config]</code> may need to be configured
for the project.</p>
</blockquote>
<p>When redirecting from URLs that do not end with <code>.html</code> or <code>.htm</code>, the redirect page
is generated at the url with <code>/index.html</code> appended.
For example if there is a redirect from <code>/old-image.png</code> to
<code>/new-image.png</code>, the redirect page will be generated at
<code>/old-image.png/index.html</code>.
This is done with the hope that the web server, without extra
configuration, will respond to a request for <code>/old-image.png</code> with a
content-type header of <code>text/html</code>.</p>
<h3>Redirect Map</h3>
<p>If a <code>map_file</code> is configured in the plugin configuration file (<code>configs/redirect.ini</code>),
a <em>map file</em> will be generated in the output tree.</p>
<p>The map file is in a format suitable for inclusion in an <em>nginx</em><ahref="https://nginx.org/en/docs/http/ngx_http_map_module.html"rel="nofollow">map block</a>.
Assuming there is a single redirect from <code>/old-page</code> to <code>/new-page</code>, the contents
of the map file would be:</p>
<pre><code>/old-page/ /replacement-page/;
</code></pre>
<p>Assuming that <code>map_file</code> is set to <code>.redirect.map</code>, the salient parts
of an <em>nginx</em> configuration file that utilizes the redirect map might
Please enable JavaScript to view the <ahref="https://disqus.com/?ref_noscript"
rel="nofollow">comments powered by Disqus.</a>
</noscript>
</div>
</div>
</div>
</div>
</div>
</div>
<divclass="bottomsummary">
<divclass="container">
</div>
</div>
<footer>
<divclass="container">
<divclass="row">
<divclass="col-sm-4 icon-bar">
<ahref="https://github.com/lektor/lektor/"title="Lektor on GitHub"
><iclass="fa fa-github"></i></a>
<ahref="https://github.com/lektor/lektor/issues/"title="Report Issues for Lektor"
><iclass="fa fa-bug"></i></a>
<ahref="https://twitter.com/getlektor"title="Find Lektor on Twitter"
><iclass="fa fa-twitter"></i></a>
<ahref="https://gitter.im/lektor/lektor"title="Chat on Gitter"
><iclass="fa fa-comment"></i></a>
<ahref="https://github.com/lektor/lektor-website/tree/master/content/plugins/lektor-redirect/contents.lr"title="View source for this page"><iclass="fa fa-code"></i></a>
</div>
<divclass="col-sm-8">
<ahref="../../license/">License & Copyright</a> •
<ahref="../../contact/">Contact</a> •
Made with <iclass="fa fa-fw fa-heart"title="Heart"><spanhidden>Heart</span></i> in Carinthia