Using mod_speling with multi-level htaccess and rewriterules
Posted
by
michaelcgorman
on Pro Webmasters
See other posts from Pro Webmasters
or by michaelcgorman
Published on 2012-11-09T16:38:26Z
Indexed on
2012/11/09
17:21 UTC
Read the original article
Hit count: 251
We recently switched formats for managing our 301s. For the most part, everything went well, but it seems to have stopped mod_speling from working properly. Here's what we changed:
old /var/www/html/.htaccess:
RewriteEngine on
RewriteBase /
# Change SHTML to HTML
RewriteRule ^(.*)\.shtml$ $1.html [R=permanent,L]
# Change PCF to HTML ('cause, you know, we probably have CMS users like that...)
RewriteRule ^(.*)\.pcf$ $1.html [R=permanent,L]
# Force WWW subdomain for all requests
RewriteCond %{HTTP_HOST} !^www.example.edu$ [NC]
RewriteRule ^(.*)$ http://www.example.edu/$1 [R,L]
# User accounts are on sun.example.edu
RedirectMatch ^/~(.*)$ http://sun.example.edu/~$1
# Remove index.html at the end of URLs
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . %1 [R=301,NE,L]
Redirect 301 /academics/calendar2012-13.html http://www.example.edu/academics/calendar.html
Redirect 301 /academics/departments/ http://www.example.edu/majors/
Redirect 301 /academics/Pre-Medical.pdf http://www.example.edu/academics/Pre-Medicine.pdf
Redirect 301 ...
new /var/www/html/.htaccess:
RewriteEngine on
RewriteBase /
# Change SHTML to HTML
RewriteRule ^(.*)\.shtml$ $1.html [R=permanent,L]
# Change PCF to HTML ('cause, you know, we probably have CMS users like that...)
RewriteRule ^(.*)\.pcf$ $1.html [R=permanent,L]
# Force WWW subdomain for all requests
RewriteCond %{HTTP_HOST} !^www.example.edu$ [NC]
RewriteRule ^(.*)$ http://www.example.edu/$1 [R,L]
# User accounts are on sun.example.edu
RedirectMatch ^/~(.*)$ http://sun.example.edu/~$1
# Remove index.html at the end of URLs
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . %1 [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) 404/$1
And then we added a new file at /var/www/html/404/.htaccess:
RewriteEngine on
RewriteBase /404
RewriteRule ^academics/calendar2012-13.html$ /academics/calendar.html [R=302,L]
RewriteRule ^academics/departments/$ /majors/ [R=301,L]
RewriteRule ^academics/Pre-Medical.pdf$ /academics/Pre-Medicine.pdf[R=301,L]
RewriteRule ...
I do have (Webmin-based) access to the httpd.conf (though we don't want to store all our 301s there, if possible). We're running Apache 2.2.15 on RHEL 6 on a server in our own data center.
Like I said, the only problem we're seeing is that mod_speling isn't doing its magic anymore. The new format has so many advantages over the old that we really don't want to go back, but mod_speling is so nice to have that we'd also really like it to work if possible. Any ideas for how we might be able to fix mod_speling?
© Pro Webmasters or respective owner