Anders
Anders

Reputation: 12736

Rewrite to case insensitive urls in CodeIgniter site?

I'm using CodeIgniter for a web application, and now I have an urgent question: I just discovered that urls are case sensitive in Linux based servers, and I have just moved a site from Windows to Linux. This means links to the site don't work anymore where there are now all lower-case urls, which were not before.

Googling I found that you should be able to do something like this in the .htaccess file:

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

But I tried that and it was not good at all...! Suddenly I got a big ugly error page staring at me instead, saying that there must be something wrong with the Tomcat server or something like that. Needless to say I removed those lines immediately!

But why didn't it work then, and what should I do instead?

Any help would be greatly appreciated.

Upvotes: 4

Views: 4179

Answers (3)

Vikrant Naik
Vikrant Naik

Reputation: 34

If case insensitive routes are required, do below changes to URI.php

Location of File: system/core/URI.php

Find $this->_parse_request_uri() and replace it with strtolower($this->_parse_request_uri())

Upvotes: 0

Ken Gregory
Ken Gregory

Reputation: 7400

Code igniter supports regular expressions - if you'd like to be explicit in the definition of your routes, define them in this fashion to be case insensitive:

$route['(?i)(about\/contact)'] = 'about/contact';

Upvotes: 8

Anders
Anders

Reputation: 12736

Actually found out that it was quite easy, surprised that no one answered this (perhaps it isn't the correct way, but I would think so...):

I just added some routes in the routes.php file in the config folder:

$route['About/Contact'] = "about/contact";

And so on...

Upvotes: -1

Related Questions