Over a decade ago, I decided I wanted my article URLs to live at my site’s root path / instead of a subpath (like /blog or /articles) “for SEO purposes.” That made sense when I had a few dozen articles and hosted with WordPress. Today, I have nearly 3,000 articles generated as a flat HTML files with Hugo, and navigating my file system on the server is an unruly mess! I finally decided to fix this, moving all of my articles to the /articles subdirectory. But I also wanted to sure that all of the many, many links to past articles continued to work. That’s easy to do when they already live in a subdirectory, and much harder when they’re at the root. I didn’t want to go through an individually create redirects for all 2,929 articles. But I also can’t just blanket redirect everything in the root to /articles, because I have lots of other valid root pages. Luckily, so .htaccess magic came to the rescue! <IfModule mod_rewrite.c> # 1. Enable the rewrite engine RewriteEngine On # 2. If the…
No comments yet. Log in to reply on the Fediverse. Comments will appear here.