Open joewiz opened 8 years ago
Here was how I implemented this on the old hsg. Question: Are there any obvious performance concerns with this approach? Or should I just give it a try and run the load tests to see how it performs?
from controller.xql
(: Handle retired URLs - redirect to new URLs :)
else if (url:is-retired-url($exist:path)) then
local:redirect-with-301(url:get-revised-url($exist:path))
from url-rewriting.xqm
(: === Functions for handling retired URLS === :)
declare function url:is-retired-url($url as xs:string) as xs:boolean {
exists(collection('/db/cms/apps/site-structure/retired-urls')//url[old = $url])
};
declare function url:get-revised-url($url as xs:string) as xs:string {
collection('/db/cms/apps/site-structure/retired-urls')//url[old = $url]/new/string()
};
again, from controller.xql
declare function local:redirect-with-301($absolute-path) {
local:forward('services/301.xq',
local:add-parameter('path', $absolute-path)
)
};
services/301.xq
(: an attempt at an actual 301 response :)
let $path := request:get-parameter('path', '')
return
(
response:set-status-code(301)
,
response:set-header('Location', $path)
)
retired-urls/milestones.xml
<retired-urls>
<page-id>milestones/milestones-articles</page-id>
<data-collection>/db/cms/apps/tei-content/data/milestones</data-collection>
<public-website-collection>/milestones</public-website-collection>
<created-by>cozensef</created-by>
<created-datetime>2013-10-29T14:46:00.000-04:00</created-datetime>
<last-updated-by>wicentowskijc</last-updated-by>
<last-updated-datetime>2013-10-30T14:18:41.623-04:00</last-updated-datetime>
<description>New periodization and cool URL-style article ids for Milestones articles</description>
<url>
<old>/milestones/1750-1775/Incidents</old>
<new>/milestones/1750-1775/incidents</new>
</url>
<url>
<old>/milestones/1750-1775/FrenchIndianWar</old>
<new>/milestones/1750-1775/french-indian-war</new>
</url>
<url>
<old>/milestones/1750-1775/AlbanyPlan</old>
<new>/milestones/1750-1775/albany-plan</new>
</url>
...
</retired-urls>
collection.xconf
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index>
<create qname="page-id" type="xs:string"/>
<create qname="old" type="xs:string"/>
<create qname="new" type="xs:string"/>
</index>
</collection>
Retired URLs for FAQ edits at https://github.com/HistoryAtState/other-publications/commit/c9d8f44659eb4f5ad4f199b0ba2354007bfe6986: retired-urls-faq.xml.zip