如何在Linux服务器中使URL不区分大小写

时间:2022-07-05 19:21:22

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.

我正在使用部署在Linux服务器上的网站。我对此做了一些小改动。我有文件夹阅读。要求是,如果我输入URL localhost:80 / tom / Read或../READ或/ read,它需要导航到read文件夹中的read.php。

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

我在根目录下创建了一个.htaccess文件。通过查看此处提到的页面,在文件中提到以下代码

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?

我是Linux环境的新手。我不知道mod_speling。那是一个档案吗?它将位于Linux服务器中的哪个位置?

4 个解决方案

#1


25  

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

您可以使用mod_speling模块轻松地使apache webserver忽略大小写,这是标准apache发行版的一部分:

CheckSpelling On
CheckCaseOnly On

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

重新启动httpd后,您可以将读取作为读取或读取或读取。

#2


23  

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

嗨,我终于得到了解决方案。将以下代码放在/etc/httpd/conf/httpd.conf中。

LoadModule speling_module modules/mod_speling.so

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

Then restart httpd:

然后重启httpd:

sudo service httpd restart

And finally verify it is enabled:

最后验证它已启用:

sudo httpd -M | grep speling

That should yield speling_module (shared)

这应该产生speling_module(共享)

Thanks for the help for all..

感谢所有人的帮助..

#3


2  

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

首先安装speling_module。然后在httpd.conf文件中包含LoadModule speling_module modules / mod_speling.so然后包含

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

#4


1  

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.

嗨不确定这是否有帮助,但这是我使用的简单工作,它使用一个非常基本的PHP页面,但它适用于我需要它的网站。

Place this code in the htaccess file

将此代码放在htaccess文件中

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

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

然后我创建了一个php文件,如下所示..

 <?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

基本上它将引用url - > store作为$ aurl

it then makes it lowercase -> stores as $lurl

它然后使它成为小写 - >商店为$ lurl

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

如果它们不匹配,则尝试显示小写网址($ 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..

如果失败则页面不存在,引用URL现在是相同的($ lurl == $ aurl),因此它会重定向到正确的404页面或者可以显示一些额外的代码。

#1


25  

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

您可以使用mod_speling模块轻松地使apache webserver忽略大小写,这是标准apache发行版的一部分:

CheckSpelling On
CheckCaseOnly On

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

重新启动httpd后,您可以将读取作为读取或读取或读取。

#2


23  

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

嗨,我终于得到了解决方案。将以下代码放在/etc/httpd/conf/httpd.conf中。

LoadModule speling_module modules/mod_speling.so

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

Then restart httpd:

然后重启httpd:

sudo service httpd restart

And finally verify it is enabled:

最后验证它已启用:

sudo httpd -M | grep speling

That should yield speling_module (shared)

这应该产生speling_module(共享)

Thanks for the help for all..

感谢所有人的帮助..

#3


2  

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

首先安装speling_module。然后在httpd.conf文件中包含LoadModule speling_module modules / mod_speling.so然后包含

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

#4


1  

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.

嗨不确定这是否有帮助,但这是我使用的简单工作,它使用一个非常基本的PHP页面,但它适用于我需要它的网站。

Place this code in the htaccess file

将此代码放在htaccess文件中

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

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

然后我创建了一个php文件,如下所示..

 <?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

基本上它将引用url - > store作为$ aurl

it then makes it lowercase -> stores as $lurl

它然后使它成为小写 - >商店为$ lurl

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

如果它们不匹配,则尝试显示小写网址($ 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..

如果失败则页面不存在,引用URL现在是相同的($ lurl == $ aurl),因此它会重定向到正确的404页面或者可以显示一些额外的代码。