• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
url case sensitivity

I'm been using code igniter for a while now, trying to get to grips with mod_rewite too in order to remove the relevent index.php.

Its all working on my Wampserver. However I've got a really odd problem which i can't pin down to an issue with Code igniter or my mod_rewrite.

basically accessing the path


I get the login page as expected.

however accessing


returns a page not found!

The strange thing is that both


successfully return my welcome page, hence I can only think that the fault is somewhere within the CodeIgniter system itself, rather than my .htaccess ( which i've added below)

Its odd as well as I'm using a windows file system so my understanding is case should be completely interchangeable.

Has anyone experienced this problem before? Its a massive issue. to be honest i don't care if its EITHER uppercase or lower case, but that fact that i can get to my main page either way and only one of the instances actually works make is aweful.

I know there isn't much infomation here but if anyone can help..?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(js|css|images|robots\.txt)

RewriteRule ^(.*)$ index.php/$1 [L]  

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(Main(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

<Files "index.php">
AcceptPathInfo On

OK, in an effort to identify this further I've done the following;

downloaded a new instance of codeigniter and unzipped into my directory "casetest" in the root of my Apache 2.2 www directory

I can now access the welcome page now via


great. I've then simplified my .htaccess to the following;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(js|css|images|robots\.txt)

RewriteRule ^(.*)$ index.php/$1 [L]

I've then added the following to my welcome.php controller
public function testing()
  echo 'i got to testing';

and thats all i've done. so its as close to vanilla as i can get it.

so now,
return 'my i got to testing'



returns me a 404 error generated by code igniter ( with formatting etc )

I'm sure i'm doing something unbelievably stupid somewhere for a vanilla install to fail soo quickly but i'm completely lost as to what..?

further investigation on the _validate_request function inside Router.php;

a var dump for my failed caseTest gives me 3 segments;
  0 => string 'caseTest' (length=8)
  1 => string 'Welcome' (length=7)
  2 => string 'testing' (length=7)
And the working instance, all lower case is;
  0 => string 'Welcome' (length=7)
  1 => string 'testing' (length=7)

I'm guessing now i must be missing some sort of configuration that means the first segment is being included when it shouldn't be...

OK.. so i found the problem, but i need someone to tell me if its a bug or not....

it turns out when trying to identify the url it runs the following code in the URI.php file at line 200

elseif (strpos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
   $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));

which is basically stripping off the directory name which contains the raw index.php file. this is fine for most things, and fine for linux where the path is case sensitive anyway.

However when routing to the Welcome/index action via the default handler this code is ignored, meaning that my caseTest and casetest don't experience anything different on the starting page.

however once the user has browsed to my opening page and clicked a link, the url happily strips the correctly cased casetest from its url, but not the incorrectly cased. meaning that the user is ALWAYS presented with a nice front login screen but every link is broken.

I couldn't find anything that allowed me to specify the case sensitivity of the directory to fix i replaced the strpos with stripos;

elseif (stripos($uri, dirname($_SERVER['SCRIPT_NAME'])) === 0)
   $uri = substr($uri, strlen(dirname($_SERVER['SCRIPT_NAME'])));
and hey presto now my url is case insensitive and i can access the application from either url!

So... personally i think this is a bug unless there is a specific reason for this?

Why does this matter? The only thing that really matters is that the links are all created the same, NOT whether you can get to the same URL using a mixture of upper/lowercase. If you have 2 different links like www.yoursite.com/something and www.yoursite.com/Something, you will probably get penalized by search engines for having duplicate content. If you only use www.yoursite.com/something OR www.yoursite.com/Something for your links, then you'd be ok, but if you use both you will feel the wrath of google Smile

Who cares if a link is www.yoursite.com/something but someone can still access by using an upper case version? No one really does that. They click links. So if all of your links lead to the correct content, this is kind of moot.

thanks for your reply Cronix

Perhaps i didn't explain myself properly;

www.yoursite.com/Something and www.yoursite.com/something get you to the same site and front page just fine. The point is on www.yoursite.com/Something all the links are broken on a Windows system once you get there.

In Linux www.yoursite.com/Something wouldn't work anyway because Apache wouldn't find the "Something" directory in the first place ( case sensitivity of the OS directory name) so we get the expected 404. Thats great and how I would hope it to work, not finding anything at all under the Something path.

But the fact it finds just the front page with everything else broken means its bugged in Windows. I also consider it quite a serious bug. If someone types the URL ( I'm actually writing a web application, not a searchable website, so this is very possible) without adhering to the case (they are users after all!) they'll still appear to have hit the site and assume they'd typed correctly, but it would be the version of the site without a single working link on it.

I agree with your point on Google however. Maybe it needs to return a 404 instead, inline with a Linux install?

I hope that makes a little more sense.

It certainly seems like something worth bringing up. I'm not on Windows so I can't debug properly, otherwise I'd tinker with it.

I'd create a issue (or even better, a pull request with a solution) on Github.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.