homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewrite syntax?!?
config for rewriting url's without trailing slash and all lower-case

10+ Year Member

Msg#: 3282 posted 7:48 pm on Apr 5, 2005 (gmt 0)

This may be a simple question, but I'm having trouble understanding the syntax for mod_rewrite. I'm running a site that has tons of aliases and redirects, but people always type them in wrong. They either use the wrong case, or they add a trailing slash to a redirect that points to a file. I want to add a rewrite rule that will remove all trailing slashes, and convert the url case to lowercase no matter what a user enters into the URL field. Can someone PLEASE help me?



WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 3282 posted 8:20 pm on Apr 5, 2005 (gmt 0)


Welcome to WebmasterWorld!

See the description of RewriteMap in mod_rewrite [httpd.apache.org]. It can call the system "tolower" function to force lowercase. RewriteMap is available in server context, and is not available in per directory (.htaccess) context. Then there is mod_speling [httpd.apache.org] which can correct a few errors in the URL, but at the cost of much slower server performance.

An alternative is to create a custom error document using php or similar, and use it to figure out what URL most closely matches the one that was typed-in. You can use mod_rewrite to check for "file exists" and steer all non-existent requests to this script. If it can fix the URL, fine, then return a 301 redirect to the corrected URL. If not, return a 404-Not Found. Doing this correctly will keep you out of trouble with the search engines.

As far as removing a trailing slash, that's a simple rewrite, and I recommend the documentation cited in our forum charter [webmasterworld.com] to you.

Other than that, take a hard look at your site navigation and try to make it more user-friendly, so that you get fewer type-ins, and pages are easier to find if you issue a 404 and then meta-refresh them to your home page to start over.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved