23

I am working a website which is deployed on a Linux server. I have small changes to do on that. I have folder read. The requirement is that if I enter the URL localhost:80/tom/Read or ../READ or /read it needs to navigate to read.php inside a read folder.

I created a file .htaccess under a root directory. Placed following code mention below in the file by seeing the page mentioned here

RewriteEngine On
RewriteBase /tom/

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

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteRule ![A-Z] - [S=26]
RewriteRule ^(.*)(A)(.*)$ $1a$3 [N,R=301]
RewriteRule ^(.*)(B)(.*)$ $1b$3 [N,R=301]
RewriteRule ^(.*)(C)(.*)$ $1c$3 [N,R=301]
RewriteRule ^(.*)(D)(.*)$ $1d$3 [N,R=301]
RewriteRule ^(.*)(E)(.*)$ $1e$3 [N,R=301]
RewriteRule ^(.*)(F)(.*)$ $1f$3 [N,R=301]
RewriteRule ^(.*)(G)(.*)$ $1g$3 [N,R=301]
RewriteRule ^(.*)(H)(.*)$ $1h$3 [N,R=301]
RewriteRule ^(.*)(I)(.*)$ $1i$3 [N,R=301]
RewriteRule ^(.*)(J)(.*)$ $1j$3 [N,R=301]
RewriteRule ^(.*)(K)(.*)$ $1k$3 [N,R=301]
RewriteRule ^(.*)(L)(.*)$ $1l$3 [N,R=301]
RewriteRule ^(.*)(M)(.*)$ $1m$3 [N,R=301]
RewriteRule ^(.*)(N)(.*)$ $1n$3 [N,R=301]
RewriteRule ^(.*)(O)(.*)$ $1o$3 [N,R=301]
RewriteRule ^(.*)(P)(.*)$ $1p$3 [N,R=301]
RewriteRule ^(.*)(Q)(.*)$ $1q$3 [N,R=301]
RewriteRule ^(.*)(R)(.*)$ $1r$3 [N,R=301]
RewriteRule ^(.*)(S)(.*)$ $1s$3 [N,R=301]
RewriteRule ^(.*)(T)(.*)$ $1t$3 [N,R=301]
RewriteRule ^(.*)(U)(.*)$ $1u$3 [N,R=301]
RewriteRule ^(.*)(V)(.*)$ $1v$3 [N,R=301]
RewriteRule ^(.*)(W)(.*)$ $1w$3 [N,R=301]
RewriteRule ^(.*)(X)(.*)$ $1x$3 [N,R=301]
RewriteRule ^(.*)(Y)(.*)$ $1y$3 [N,R=301]
RewriteRule ^(.*)(Z)(.*)$ $1z$3 [N,R=301]

But it is not working.

I am new to Linux environment. I don't know about mod_speling. Is that a file? Where it will be located in Linux server?

hoeni
  • 3,031
  • 30
  • 45
sonorita
  • 771
  • 2
  • 8
  • 20
  • 1
    I would question the specification here. This would lead to more problems, for example with bot indexing. – Denys Séguret Feb 11 '13 at 14:46
  • possible duplicate of [Case Insensitive URLs with mod\_rewrite](http://stackoverflow.com/questions/1998156/case-insensitive-urls-with-mod-rewrite) – Marc B Feb 11 '13 at 14:47
  • Yeah, the requirement is likely to be a problem in itself. That said, there is an Apache module that can help (it's the one that can deal with requests that are a bit off, and serve an alternative... I forget the name) Edit: it's `MultiViews` – Pekka Feb 11 '13 at 14:48
  • Hi dystroy.. I am new to php. I just google for the solution and wrote as above.. If u have solution please let me known.. – sonorita Feb 11 '13 at 14:49
  • possible duplicate of [How do I make Linux server urls case insensitive?](http://stackoverflow.com/questions/14813755/how-do-i-make-linux-server-urls-case-insensitive) – geocodezip Feb 11 '13 at 14:56
  • Next time edit your original question instead of creating another one! How far does your permission reach on the webserver? Do you have access to SSH? – s.lenders Feb 11 '13 at 14:56

4 Answers4

36

You can easily make the apache webserver ignore the case by using the mod_speling module, which is part of the standard apache distribution:

CheckSpelling On
CheckCaseOnly On

After restarting httpd you can access read as Read or READ or read.

hoeni
  • 3,031
  • 30
  • 45
  • Hi Hoeni .. I placed the above 2 line code in .htaccess with already present code.Then restarted. Its not working. Any suggestion – sonorita Feb 12 '13 at 05:30
  • 1
    I'm wondering if there are any performance considerations when using this. I have a large Sencha app that has this problem. 390MB of files all of mixed case and referenced differently throughout.. – Michael Fever Jan 31 '14 at 17:25
  • 37
    Am I the only one that finds it ironic that the module to check spelling is misspelled? – Dave Oct 01 '15 at 16:32
  • Yes, it has performance issue, but its a quick fix http://blog.servergrove.com/2010/08/24/fixing-problems-with-case-sensitive-urls/ – Aditya Mittal May 19 '16 at 21:54
  • I doubt in any modern operating system this has a serious performance penalty (compared to the whole request) just for checking the mere existence of a few alternative filenames in the same directory. – hoeni May 20 '16 at 07:17
  • 3
    @Dave: It's very intentional: https://httpd.apache.org/docs/2.4/mod/mod_speling.html#comment_6522 – Emil Stenström Jul 31 '17 at 20:12
  • @EmilStenström I don't see anything on that page that talks about the misspelling. I can find one other search result that corroborates it but doesn't provide a reason. I assume it's just a joke? – Chris Feb 11 '22 at 20:47
  • @Chris Yes, the comment my link referred to is gone now, and I've looked around to fine an alternative source. We've got to assume. – Emil Stenström Feb 12 '22 at 21:08
  • This module is really nice, but beware about this : "more than one document with a close match was found, then the list of the matches is returned to the client, and the client can select the correct candidate (300 - Multiple Choices)." . in my case, i was trying to match images(somehow mixed-cses) and the module suggested a bunch of images in the directory that was closely matched :( – Shan May 18 '22 at 07:52
34

Hi I got the solution finally. Placed the below code in /etc/httpd/conf/httpd.conf.

LoadModule speling_module modules/mod_speling.so

<IfModule mod_speling.c>
  CheckSpelling On
  CheckCaseOnly On
</IfModule>

Then restart httpd:

sudo service httpd restart

And finally verify it is enabled:

sudo httpd -M | grep speling

That should yield speling_module (shared)

Thanks for the help for all..

radtek
  • 34,210
  • 11
  • 144
  • 111
sonorita
  • 771
  • 2
  • 8
  • 20
  • The IfModule directive should make no difference at all, as it's just for avoiding errors when you **don't** have the module loaded. (http://httpd.apache.org/docs/2.4/mod/core.html#ifmodule). When you have errors without it, the mod_speling module is not loaded at all. – hoeni Feb 14 '13 at 16:01
  • 4
    The `speling` module does not seem to be enable by default on Debian (probably Ubuntu as well). To enable it use the command `sudo a2enmod speling`. – Dave Oct 01 '15 at 16:48
  • 6
    I think the module being spelled incorrectly is absolutely fantastic. – ScottMcGready Mar 25 '16 at 23:31
  • Great and Working answear! – NoWomenNoCry Oct 30 '17 at 08:36
  • All the people here typing this without knowing that mod speling not working with mod rewrite ... – Alin Razvan Mar 02 '21 at 07:38
5

First install speling_module. Then include LoadModule speling_module modules/mod_speling.so in httpd.conf file and then include

<IfModule mod_speling.c>
     CheckSpelling On
     CheckCaseOnly On
</IfModule>
in httpd.conf, then restart httpd service using service httpd restart command.

0

Hi not sure if this helps but this is the simple workabout i have used, it uses a very basic php page but it works for the site i needed it to.

Place this code in the htaccess file

 AddType application/x-httpd-php .html .htm
 ErrorDocument 404 /404.php

I have then created a php file wit the following..

 <?php
 $aurl = $_SERVER['REQUEST_URI'];
 $lurl = strtolower($aurl);

 if($aurl != $lurl){
header('location:'.$lurl);
 } else {
header('location:/404.html');
 }
 ?>

Basically it gets the referring url -> stores as $aurl

it then makes it lowercase -> stores as $lurl

if they are not matching it then trys to display the lowercase url ($lurl)

If that fails the page does not exist, the refering url is now the same ( $lurl == $aurl ) so it then redirects to a proper 404 page or can display some extra code..

South Coast Web
  • 440
  • 2
  • 8
  • 21
  • 3
    Why the `} else { header('location:/404.html'); }`? Shouldn't it just be left alone without redirect if `$aurl == $lurl`? – tnschmidt Jan 22 '16 at 17:58