Mobile app version of vmapp.org
Login or Join
Carla537

: Using mod_speling with multi-level htaccess and rewriterules We recently switched formats for managing our 301s. For the most part, everything went well, but it seems to have stopped mod_speling

@Carla537

Posted in: #Apache #Apache2 #ModRewrite

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$ .html [R=permanent,L]

# Change PCF to HTML ('cause, you know, we probably have CMS users like that...)
RewriteRule ^(.*).pcf$ .html [R=permanent,L]

# Force WWW subdomain for all requests
RewriteCond %{HTTP_HOST} !^www.example.edu$ [NC]
RewriteRule ^(.*)$ www.example.edu/ [R,L]

# User accounts are on sun.example.edu
RedirectMatch ^/~(.*)$ sun.example.edu/~
# 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 www.example.edu/academics/calendar.html Redirect 301 /academics/departments/ www.example.edu/majors/ Redirect 301 /academics/Pre-Medical.pdf www.example.edu/academics/Pre-Medicine.pdf Redirect 301 ...


New /var/www/html/.htaccess:

RewriteEngine on
RewriteBase /

# Change SHTML to HTML
RewriteRule ^(.*).shtml$ .html [R=permanent,L]

# Change PCF to HTML ('cause, you know, we probably have CMS users like that...)
RewriteRule ^(.*).pcf$ .html [R=permanent,L]

# Force WWW subdomain for all requests
RewriteCond %{HTTP_HOST} !^www.example.edu$ [NC]
RewriteRule ^(.*)$ www.example.edu/ [R,L]

# User accounts are on sun.example.edu
RedirectMatch ^/~(.*)$ sun.example.edu/~
# 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/


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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Carla537

1 Comments

Sorted by latest first Latest Oldest Best

 

@Eichhorn148

mod_speling and mod_rewrite apply their rules during the same phase. If rewrite touches a URL it generally won't pass the url on to mod_speling. You can use the "pass through" [PT] flag on any rewrite rule that is preventing mod_speling from doing its magic. If the [PT] flag is in place, then mod_speling can still do its job.

The other thing that I do is put a script in place for the 404 handler. This allows me to examine the url in the script and issue redirects based on rules such as case sensitivity, truncation that can be inferred, characters appended after ".html" and so on. I stopped using mod_speling when I found I could implement a 404 handler that did a better job with the 404 errors that I was actually getting.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme