How to solve a URL capitalisation issue?

Discussion in 'Site & Server Administration' started by LawnchairLarry, Oct 25, 2008.

  1. #1
    I have a problem with a website on a server that is set to destinguish between URLs or files with capitals in them and the same ones without capitals. For example, the two URLs below are clearly the same (there really is only one file on that location, I've checked that), but are regarded as two different URLs:
    http://www.MyDomain.com/File.HTML
    http://www.mydomain.com/file.html
    Code (markup):
    How do I set the server so that it understands that both versions are the same and to automatically "redirect" (?) all URLs or files with capitals in them to the non-capitalised URLs or files? Cheers for your help!
     
    LawnchairLarry, Oct 25, 2008 IP
  2. kailash

    kailash Well-Known Member

    Messages:
    1,248
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    190
    #2
    It seems that your domain is hosted on Linux server. Please note that Linux is case sensitive hence file.htm and File.HTM will consider as two different file.

    Kailash
     
    kailash, Oct 25, 2008 IP
  3. deadlychaos25

    deadlychaos25 Guest

    Best Answers:
    0
    #3
    You need to add a redirect in your htaccess.
    Just google it and get it.
     
    deadlychaos25, Oct 25, 2008 IP
  4. LawnchairLarry

    LawnchairLarry Well-Known Member

    Messages:
    318
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    118
    #4
    It would be nice and useful if you'd tell me what to look for, instead of just telling me to change the .htaccess file.
     
    LawnchairLarry, Oct 26, 2008 IP
  5. mortenb

    mortenb Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    deadlychaos25 is right. Setting it up in .htaccess would be an easy fix. Put the following in your .htaccess file.

    RewriteEngine on
    RewriteRule ^file.html$ /file.html [NC,L]

    What is does is rewrite any upper- and/or lowercased version of file.html to file.html. The NC in the [NC,L] part means case insensitive.



    Another option would be to enable mod_spelling on your server, but that is not really a good idea.
     
    mortenb, Oct 26, 2008 IP
  6. LawnchairLarry

    LawnchairLarry Well-Known Member

    Messages:
    318
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    118
    #6
    Mange tak, Morten. I'll add that to my .htaccess file. The problem with the URL rewrite is that it will only work for the file types that I include in the mod_rewrite. Given that there are a few hundred files on the Apache server with various file extensions, there is a reasonable chance that I forget to include one or more. Is there perhaps a way to include all the files of all the file extensions using one or only a few lines of code?
     
    LawnchairLarry, Oct 26, 2008 IP
  7. JPC-NickO

    JPC-NickO Guest

    Messages:
    69
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,

    Unfortunately, this cannot be properly dealt with using mod_rewrite. You are better off checking to see if your provider allows mod_speling.

    Please note that the domain is not case-sensitive only the path is.

    I highly recommend to all our clients to adopt a naming structure that does not use upper-case letters, spaces, and other characters that must be escaped on a Unix variant file system.
     
    JPC-NickO, Oct 26, 2008 IP
  8. mortenb

    mortenb Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    As JPC-NickO writes, this is not really something that should be dealt with in .htaccess for a large number of files. mod_spelling on the other hand isn't much better and is in this case really just a cure for a problem that shouldn't have existed in the first place.

    The best solution would be to make sure all your files are lowercased. I know this isn't the answer you wanted to hear but I really don't have another one for you :(
     
    mortenb, Oct 27, 2008 IP
  9. mortenb

    mortenb Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Well, you could set up a rewritemap, but that would still require you to have an updated map of all your files with the exact capitalization and if you are going to do that, then you might as well just rename all the files to their lowercased versions.
     
    mortenb, Oct 27, 2008 IP
  10. mortenb

    mortenb Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Let me know if you do decide to lowercase all of them. I have a nice little shellscript that will do it for you.
     
    mortenb, Oct 27, 2008 IP
  11. LawnchairLarry

    LawnchairLarry Well-Known Member

    Messages:
    318
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    118
    #11
    Cheers for the offer, Morten, but after some consideration I've concluded that it would cost me too much time and effort. And the website I am working on is just not worth it. Thanks again for your help.
     
    LawnchairLarry, Oct 28, 2008 IP