From 3d4da5ac6000a4871c5caa80d1e61f2782da3069 Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Sat, 2 Dec 2023 23:27:35 -0600 Subject: feat: finish converting md to org --- blog/2021-10-09-apache-redirect.org | 70 +++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 34 deletions(-) (limited to 'blog/2021-10-09-apache-redirect.org') diff --git a/blog/2021-10-09-apache-redirect.org b/blog/2021-10-09-apache-redirect.org index 497fada..f925f31 100644 --- a/blog/2021-10-09-apache-redirect.org +++ b/blog/2021-10-09-apache-redirect.org @@ -1,45 +1,47 @@ -+++ -date = 2021-10-10 -title = "Apache Redirect HTML Files to a Directory" -description = "Learn how to conveniently rewrite certain Apache web file URLs to directories with the Apache web server." -draft = false -+++ - -## The Problem - -After recently switching static site generators (SSG), my blog URLs changed with -no option to preserve the classic `.html` extension at the end of my blog -post URLs. - -I really disliked using my old SSG ([Jekyll](https://jekyllrb.com)) and prefer -my new tool ([Zola](https://www.getzola.org)) much more, so I was determined to -figure out a way to get the proper redirect set up so that people who find my -posts online aren't constantly met by 404 errors. - -## The Solution - +#+title: Apache Redirect HTML Files to a Directory +#+date: 2021-10-10 + +** The Problem +:PROPERTIES: +:CUSTOM_ID: the-problem +:END: +After recently switching static site generators (SSG), my blog URLs +changed with no option to preserve the classic =.html= extension at the +end of my blog post URLs. + +I really disliked using my old SSG ([[https://jekyllrb.com][Jekyll]]) +and prefer my new tool ([[https://www.getzola.org][Zola]]) much more, so +I was determined to figure out a way to get the proper redirect set up +so that people who find my posts online aren't constantly met by 404 +errors. + +** The Solution +:PROPERTIES: +:CUSTOM_ID: the-solution +:END: To solve this problem, I really needed to solve two pieces: -1. Redirect all blog post URL requests from `/blog/some-post.html` to - `/blog/some-post/`. -2. Ensure that no other `.html` files are redirected, such as `index.html`. +1. Redirect all blog post URL requests from =/blog/some-post.html= to + =/blog/some-post/=. +2. Ensure that no other =.html= files are redirected, such as + =index.html=. -After _a lot_ of tweaking and testing, I believe I have finally found the -solution. The solution is shown below. +After /a lot/ of tweaking and testing, I believe I have finally found +the solution. The solution is shown below. -```config +#+begin_src config RewriteEngine On RewriteCond %{REQUEST_URI} !\index.html$ [NC] RewriteRule ^(.*).html$ https://example.com/$1 [R=301,L] -``` +#+end_src -This piece of code in the Apache `.conf` or `.htaccess` file will do the +This piece of code in the Apache =.conf= or =.htaccess= file will do the following: 1. Turn on the RewriteEngine so that we can modify URLs. -2. Ignore any `index.html` files from the rule we are about to specify. -3. Find any `.html` files within the website directory and redirect it to - exclude the file extension. -4. The final piece is adding the trailing slash (`/`) at the end of the URL - - you'll notice that I don't have an Apache rule for that since Apache handles - that automatically. +2. Ignore any =index.html= files from the rule we are about to specify. +3. Find any =.html= files within the website directory and redirect it + to exclude the file extension. +4. The final piece is adding the trailing slash (=/=) at the end of the + URL - you'll notice that I don't have an Apache rule for that since + Apache handles that automatically. -- cgit v1.2.3-70-g09d2