diff --git a/.htaccess b/.htaccess new file mode 100644 index 00000000..376923b2 --- /dev/null +++ b/.htaccess @@ -0,0 +1,47 @@ +# 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. + +################################################################### +# NOTE This file is not automatically copied from the main branch to +# the asf-site (publishing) branch, so if you make changes to this +# file you need to move them manually to the asf-site branch +################################################################### + +# redirect urls to the output directory +# See https://issues.apache.org/jira/browse/INFRA-27512 +RewriteEngine On + +# Two-step flow: +# 1) Normalize extensionless URLs to a trailing slash. +# 2) Internally rewrite all non-output requests into output/. + +# Redirect extensionless, non-output URLs to the trailing-slash form +# (example: /blog/2025/12/15/post -> /blog/2025/12/15/post/). +RewriteCond %{ENV:REDIRECT_STATUS} ^$ +# Use THE_REQUEST so the original URL is honored even if server rewrites to /output/. +RewriteCond %{THE_REQUEST} \s+(/[^\s?]+) [NC] +# Skip URLs already targeting output (example: /blog/output/...). +RewriteCond %1 !/output/ +# Skip URLs that already end with a slash (example: /blog/2025/12/15/post/). +RewriteCond %1 !/$ +# Skip URLs that look like files (have an extension) (example: /blog/theme/css/style.css). +RewriteCond %1 !\.[^./]+$ +RewriteRule ^.*$ %1/ [R=301,L] + +# Rewrite all non-output requests to the Pelican output/ directory +# (example: /blog/2025/12/15/post/ -> /blog/output/2025/12/15/post/). +RewriteCond %{ENV:REDIRECT_STATUS} ^$ +RewriteCond %{REQUEST_URI} !/output/ +RewriteRule ^(.*)$ output/$1 [L] \ No newline at end of file