帮助中心 >  技术知识库 >  云服务器 >  服务器教程 >  Linux 下 Apache 忽略网站 URL 的大小写

Linux 下 Apache 忽略网站 URL 的大小写

2018-11-26 08:14:42 4958

问题现象


Linux 服务器访问路径都是区分大小写的,那么搭建了 Apache 后访问 www.landui.com/Index.html 和 www.landui.com/index.html 访问的路径是不一样的,如下图所示,实际首页是 Index.html:

image.png

处理办法


要解决这个问题,需要使用使用 Apache 的 mod_speling 模块。

注意:启动了 CheckSpelling 可能会降低 Apache 的执行效率。


全新编译安装 Apache

编译安装 Apache 时把 mod_speling 模块也编译了,如

./configure --prefix=/usr/local/apache2 --enable-so --enable-speling

修改 Apache 的配置文件 httpd.conf,加上:

LoadModule speling_module     modules/mod_speling.soCheckSpelling On

 这样就启用了 mod_speling 模块。

 

只编译安装 mod_speling 模块

假设 Apache 安装目录是 /usr/local/apache2。

  1. 确认 /usr/local/apache2/modules 目录下存在 mod_speling.so 模块。

  2. 编译 mod_speling.so 模块, 进入 Apache 源码的 modules/mappers/ 目录,运行如下命令自动编译、安装和修改 httpd.conf 文件,激活 mod_speling.so 模块:

    /usr/local/apache2/bin/apxs -c -i -a mod_speling.c
    • -c 执行编译操作。

    • -i  安装操作,安装一个或多个动态共享对象到服务器的 modules 目录。

    • -a 自动增加一个 LoadModule 行到 httpd.conf 文件,以激活此模块,若此行存在则启用之。

    • -A 与 -a 类似,但是它增加的 LoadModule 行前有井号前缀(#)。

    • -e 需要执行编辑操作,可与 -a 和 -A 选项配合使用,与 -i 操作类似,修改 httpd.conf 文件,但并不安装此模块。

    apxs 命令选项说明

   3.  在 /usr/local/apache2/conf/httpd.conf 中添加:

LoadModule speling_module     modules/mod_speling.soCheckSpelling On

   4.  重启 Apache:

/usr/local/apache2/bin/apachectl restart 或 service httpd restart


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: