mdlbear: (hacker glider)
[personal profile] mdlbear

It took a great deal longer than I expected, but I finally got the rewrite rules (Apache mod_rewrite) working to redirect URLs of the form .../Songs/foo.html to .../Songs.foo/index.html, and other related havoc. It involved the use of RewriteCond to both limit the damage to the main directory, and extract the path from REQUEST_URI so it could be redirected properly.

# .htaccess file for steve.savitzky.net/Songs

# Note that we use Index.html to keep index.html from looking like
#      it ought to be rewritten as index/lyrics.html
#      As a nice side effect, it keeps it from sorting with the 
#      song subdirectories, instead sorting it with, e.g., 0Index.html.
#
DirectoryIndex Index.html index.html

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteRule ^([-_a-z]+)/		-		[L]
 RewriteRule index.html index.html			[L]

# note that in order to use R we need to return a valid, full URL path
# use the RewriteCond to extract the directory prefix, and also to make sure 
# we don't try to rewrite anything that's already in a subdirectory.

 RewriteCond %{REQUEST_URI} ^(.*/Songs)/[^/]*$
 RewriteRule ^([-_a-z]+)\.html$ %1/$1/			[R=301]

 RewriteCond %{REQUEST_URI} ^(.*/Songs)/[^/]*$
 RewriteRule ^([-_a-z]+)\.([^/]+)$ %1/$1/$1.$2		[R=301]

## This worked, but doesn't do the redirect.
# RewriteCond %{REQUEST_URI} ^(.*/Songs)/[^/]*$
# RewriteRule ^([-_a-z]+)\.([^/]+)$ $1/$1.$2
</IfModule>

I'll probably cut over to updated site sometime this evening or tomorrow, after I've fixed more of the old links. (12:15 cut over. Song indices still need fixing, but since the old links still work it's not a problem.) It'll be safe to let many of them stand uncorrected for a while.

In other news, my weight was down to 180.2 this morning! Definitely progress in the right direction.

Most Popular Tags

Style Credit

Page generated 2026-01-08 09:52 am
Powered by Dreamwidth Studios