I want to make the URLs case insensitive.. eg: HappyBirthday.html ==> happybirthday.html in HTML, src="abcd.jpg" gives error if the file name of the image is abcd.JPG . is there any method to make them case insensitive? I use only lowercase in file names and directories.. so I want to make their access case insensitive..
Are you using apache? If so, do you have access to it's configuration file (httpd.conf)? (probably not on shared hosting)
Thanks Keyaa.. But how can it be done? what code should I put.. And ya, I use shared hosting.. So is there any other method like editing .htaccess or any PHP scripting for doing this work? Please tell me what to edit in httpd.conf file as I use Apache on local system to test files locally.. I want to try it on my local system also.
Can't think of a really good way to do this on shared hosting. Like most things it's still possible though. The best solution I could come up with is this: Set a php file as an ErrorDocument for Error 404 (File not found): this goes into .htaccess: ErrorDocument 404 /urltolower.php Code (markup): This is your urltolower.php: <?php $request = $_SERVER['REQUEST_URI']; $lower = strtolower($request); if($request == $lower) { // already lowercase, and file was not found include_once('error_404.html'); // your 'file not found'-page } else { // non-lowercase file not found - redirect to lowercase file header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $lower); } exit(); PHP: then you may create error_404.html which will be shown if a file really doesn't exist at all. And that's it (if I didn't miss something ). All your files should be lowercase like you stated though! This should work for most shared hosting configurations. With some, it "works", but they still spit out a "404 file not found" header while redirecting to the correct file - this is bad since search engines don't "see" your files this way. Give it a try, once it's on the server you can check the header that's being returned by your server with the "Live HTTP Headers" Firefox extension, for example, or I'll do it if you post back.
Thanks a Lot Keyaa... Really great thing.. Actually I dont know PHP language.. But I try to understand it.. I added the "?>" as the last line in to the PHP code you had provided. It really works with the URLs... Check it here: http://lokeshks.co.cc/ I have put an HTML file test.html and check it. It is really working.. The Access Log Shows the 301 for the uppercase ones.. I think the search engines will follow and reach the correct URLs which are in lowercase.. I have placed an image called testlog.jpg you check it, the log snapshot of the hosting. You had said to check Live HTTP Headers, It gives 200 status ok.. You check it from your side also.. This code will prevent the 404 errors if someone put our URLs in a different case. The requirement is that we must use a single casetype in out URLs and filenames... I think you can modify this code a bit so that it will neglect the part of the URL after the symbols like ? # & (dynamic URLs and Session IDs etc.) and make it work in a more wider areas... I suggest you to copyright the script if its written by you and place an Author and Copyright Notice also..
Good to see it works, never actually checked it, just wrote the code here I'm glad to tell you that the header status codes are all fine! FYI, the PHP end tag "?>" is optional, and it's use even prohibited under Zend coding guidelines. But stick to whichever coding style you like. Omitting "?>" gives you more control over control / newline characters at the end of your document. Good idea, here you go: <?php $request = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); $lower = strtolower($request); if($request == $lower) { // already lowercase, and file was not found include_once('error_404.html'); // your 'file not found'-page } else { // non-lowercase file not found - redirect to lowercase file $query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY); if($query) { $lower .= '?' . $query; } header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $lower); } exit(); PHP: Hope this works, didn't test I hereby declare it public domain Enjoy!
keyaa.. This working perfect... Great !.. You can test it just by adding ?JGDATjhsfshfsuf or any other thing to the previous test.html http://lokeshks.co.cc/TEST.html?AbCdEfGh ==> http://lokeshks.co.cc/test.html?AbCdEfGh Thanks a Lot.. I will direct my doubts in PHP directly to you through PM if I'm not satisfied with the answers in the forum.. Will you help me?
You're welcome Just to clarify: you can still have uppercase and mixed-case files and directories, they just won't be reachable via random-case, just via their exact case-sensitive filename. The script works for directories as well (should be obvious ) If you tried the forum first without getting any good replies, I'll try to help you via PM if I've got time on my hands. (Or just PM me your thread URL and I'll read it and reply there if I can help or state via PM that I can't) Good luck with your project!