大网数据广告活动
服务器运维问答

CWP7 - mod_rewrite not working?

· 52CE 我爱测

Recently I was forced to migrate from cPanel to CentOS Web Panel and there is a case-sensitive issue with file names, so "filewhatEver.jpg" is not being found in a url "filewhatever.jpg" (had no problem before in cPanel). This si…

问题原文

原帖链接 · Daniel Lemes · CC BY-SA 4.0

Recently I was forced to migrate from cPanel to CentOS Web Panel and there is a case-sensitive issue with file names, so "filewhatEver.jpg" is not being found in a url "filewhatever.jpg" (had no problem before in cPanel).

This site (there are 4 hosted) .htaccess have only the basic configuration for WordPress sites:

RewriteEngine on
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

mod_rewrite is active (listed in active modules), but when I try:

RewriteMap insensitive tolower:
RewriteRule ^[\/]*(.*)$ /${insensitive:$1} [R,L]

No luck. Edit: gives me a "Internal Server Error".

Any idea?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

Since the underlying filenames are mixed case, you can't use a rewrite map to convert the request to lowercase as it will still fail to match. (Incidentally, rewrite maps can only be defined in the main server config, not in .htaccess.)

However, you can use mod_speling (one l) to achieve the case-insensitive file matching.

You need to first make sure that mod_speling in enabled on your server. Then add the following directives to your virtual host config (or .htaccess file):

CheckSpelling on
CheckCaseOnly on

Note, however, that there is an additional overhead to using mod_speling and an external redirect is triggered when the file is found. The redirect is necessary for SEO, but will be bad for server performance if you are requesting image resources in mixed case (which is what this looks like?).

I would assume mod_speling must have been enabled by default on your old cPanel server, as this would not have been case-insensitive by default.

mod_speling is really only for incorrectly cased requests from external sites. Any internal requests should really be "fixed" to match the correct case of the underlying file.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-09-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。