SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast tentonjim's Avatar
    Join Date
    Aug 2003
    Location
    Seattle, WA USA
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    case insensitive 301 to same URL?

    Hi,
    I searched the topics here and did not see this posted, and haven't found an obvious solution on Google... it is bugging the heck out of me!
    I have a situation where there is capitalization in URLs, and people are linking to them with mixed case URLs or people are typing it in the address bar directly.
    There are thousands so I need to handle this in some sort of rewrite.

    The current URL is http://my.com/Some-Folder/Somefile.htm
    But in any number of iterations people are arriving at http://my.com/sOme-fOLder/sOmeFile.htm and getting a 404

    The .htaccess is all set up it works great, just this one situation I need to resolve.

    I need to detect anything that IS NOT in the exact case of http://my.com/Some-Folder/Somefile.htm and 301 it to that exact case URL.

    I have tried RedirectMatch and several RewriteCond/RewriteRule but the closest I have come so far ends in an infinite 301 loop.

    Is this something regular expressions could handle, and if so, any hints on what that solution might look like?

    Thanks a lot!
    Jim

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi tentonjim,

    You use the No Case Flags like
    Code:
    RewriteCond %{HTTP_HOST} !^www\.my_domain\.com [NC]
    or
    Code:
     RewriteCond %{HTTP_HOST} !^www. [NC]
    The no case flag ensures that the pattern is evaluated without case sensitivity.

    Regards,
    Steve

    Quote Originally Posted by tentonjim View Post
    Hi,
    I searched the topics here and did not see this posted, and haven't found an obvious solution on Google... it is bugging the heck out of me!
    I have a situation where there is capitalization in URLs, and people are linking to them with mixed case URLs or people are typing it in the address bar directly.
    There are thousands so I need to handle this in some sort of rewrite.

    The current URL is http://my.com/Some-Folder/Somefile.htm
    But in any number of iterations people are arriving at http://my.com/sOme-fOLder/sOmeFile.htm and getting a 404

    The .htaccess is all set up it works great, just this one situation I need to resolve.

    I need to detect anything that IS NOT in the exact case of http://my.com/Some-Folder/Somefile.htm and 301 it to that exact case URL.

    I have tried RedirectMatch and several RewriteCond/RewriteRule but the closest I have come so far ends in an infinite 301 loop.

    Is this something regular expressions could handle, and if so, any hints on what that solution might look like?

    Thanks a lot!
    Jim
    ictus==""

  3. #3
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Jim,

    The first thing to try is an Apache module named mod_spelling which corrects capitalization errors and minor typos. It's NOT enabled by default but you could ask your host to enable it for you.

    Lacking that, you could use mod_rewrite to find and replace every uppercase letter by its lower case equivalent - a nasty prospect at best. You can get sample code from my signature's tutorial that will help you with that.

    Whoops! You're using mixed case file names? Horrors! If that's the case, you'll need the same "Poor Man's RewriteMap" I just responded about in another thread but have it read the {REQUEST_FILENAME}, convert it to lower (or upper) case then, using an array for the required redirection, redirect to the CaMeL case you're using.

    Steve,

    The No Case flag works to MATCH CaMeL case (useful in your example with the {HTTP_HOST} but it will not change the case as Jim is requesting (of the {REQUEST_URI}). RewriteMap's %[tolower] will do that (change all to lower, not guess where the CaMeL is ) but I believe that you can't even use %[tolower] without enabling it in the httpd.conf.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •