3

Possible Duplicate:
Case Insensitive URLs with mod_rewrite

i have to make the urls non case sensitive.That means I have to work http://www.test.com/About.php and http://www.test.com/about.php.. I tried the below code.but it doesn't works.it shows the index page.ie, it shows the content of index page

 #Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
Community
  • 1
  • 1
asitha
  • 219
  • 1
  • 4
  • 17
  • That's what those rewrites are used for: Every URL should go `index.php` - if not that file of the request exists. So what is your actual question? – hakre Apr 20 '12 at 08:21
  • i have to make the url non case sensitive..now http://www.test.com/About.php works but http://www.test.com/about.php doesn't works.it shows the index page – asitha Apr 20 '12 at 08:28

2 Answers2

4

I've since found this question, which has an accepted answer (copied below for reference):

CheckSpelling on

It seems to be the same as (or similar enough to) your situation.

I'm not sure how / whether I can close this question as a duplicate, but it would be worth seeing if the referenced answer solves your problem first :)

Community
  • 1
  • 1
Squig
  • 862
  • 6
  • 15
0

The apache webserver on a *nix platform is case-sensitive with URLs and the *nix file-system is case-sensitive already as well.

So what you try to do within the apache configuration is not supported out of the box.

If you only have some files, you could hardcode the rules into the .htaccess as well or start to create a rewrite-map:

RewriteRule ^about.php$ About.php [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]

You might be interested as well in extending your webserver with modules (e.g. like mod_spelling) which can deal with file-name-differences between URL and on the disk.

The other alternative is that you inside index.php check for the lowercase version of the file requested $_GET['q'] and if it exists, include it and return afterwards:

$basename = strtolower(basename(realpath($_GET['q'])));
if (is_file($path = __DIR__ . '/' . $basename)) {
    include($path);
    return;
}

The way of comparing against the actual file-system depends on your concrete needs and strategy of resolvement.

hakre
  • 193,403
  • 52
  • 435
  • 836