From c0537195aaee87b0d75e69da02e80fb7c32f9b42 Mon Sep 17 00:00:00 2001 From: Ron Clabo Date: Fri, 27 Sep 2024 16:12:21 -0400 Subject: [PATCH] feature/website support for /latest/ and /absolute-latest/ redirection (#965) --- websites/site/.htaccess | 42 +++++++++++++++++++++++++++++++++++++++++ websites/site/site.ps1 | 7 +++++-- 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 websites/site/.htaccess diff --git a/websites/site/.htaccess b/websites/site/.htaccess new file mode 100644 index 0000000000..15c6b3d0c1 --- /dev/null +++ b/websites/site/.htaccess @@ -0,0 +1,42 @@ +# ----------------------------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the ""License""); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an ""AS IS"" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# ----------------------------------------------------------------------------------- + + +# The Lucene.NET site uses .htaccess to implement helpful URL redirection into the +# Lucene.NET API documentation. +# +# We use rewrite rules to enable the following: +# - /doc/latest/ redirects to the API docs corresponding to the latest +# officially released version of Lucene.NET. +# - /doc/absolute-latest/ redirects to the API docs for the absolute +# latest version, including pre-release versions. +# +# Using URLs that start with /doc/latest/ and /doc/absolute-latest/ from the +# main website content into the API documentation always points to the appropriate +# version, with [R=301] signaling permanent redirects and [L] preventing further +# rule processing. + + +RewriteEngine On + +# Redirect /docs/latest/ to /docs/3.0.3/ +RewriteRule ^docs/latest/(.*)$ /docs/3.0.3/$1 [R=301,L] + +# Redirect /docs/absolute-latest/ to /docs/4.8.0-beta00016/ +RewriteRule ^docs/absolute-latest/(.*)$ /docs/4.8.0-beta00016/$1 [R=301,L] diff --git a/websites/site/site.ps1 b/websites/site/site.ps1 index 241ebbb029..699e74c365 100644 --- a/websites/site/site.ps1 +++ b/websites/site/site.ps1 @@ -1,4 +1,4 @@ -# ----------------------------------------------------------------------------------- +# ----------------------------------------------------------------------------------- # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -68,6 +68,9 @@ if ($Clean) { Remove-Item (Join-Path -Path $SiteFolder "obj") -force -ErrorAction SilentlyContinue } +# Copy the .htaccess file to the _site directory after cleaning +Copy-Item -Path (Join-Path -Path $SiteFolder ".htaccess") -Destination (Join-Path -Path $SiteFolder "_site\.htaccess") -Force + $DocFxJson = Join-Path -Path $SiteFolder "docfx.json" $DocFxLog = Join-Path -Path $SiteFolder "obj\docfx.log" @@ -82,4 +85,4 @@ if($?) { Write-Host "starting website..." & $DocFxExe $DocFxJson --serve --port $StagingPort } -} \ No newline at end of file +}