Apache 重写条件的不区分大小写的文件检查
我有一个.htaccess文件,它测试一个特定的文件,如果有,运行一个PHP脚本,如果没有,则重定向到另一个webApache 重写条件的不区分大小写的文件检查,apache,.htaccess,mod-rewrite,case-insensitive,Apache,.htaccess,Mod Rewrite,Case Insensitive,我有一个.htaccess文件,它测试一个特定的文件,如果有,运行一个PHP脚本,如果没有,则重定向到另一个web RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/directory/$1 -f RewriteRule ^(.+\.png)$ process.php?file=$1 [QSA] RewriteRule ^(.+\.png)$ http://other.website.com/$1 我可以直接运行PHP脚本并执行重定向,但这样做速度更
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/directory/$1 -f
RewriteRule ^(.+\.png)$ process.php?file=$1 [QSA]
RewriteRule ^(.+\.png)$ http://other.website.com/$1
我可以直接运行PHP脚本并执行重定向,但这样做速度更快。但是,我需要使RewriteCond
检查不区分大小写。我尝试设置所有标志并启用拼写检查,但没有效果
RewriteEngine on
CheckSpelling on
RewriteCond %{DOCUMENT_ROOT}/directory/$1 -f [NC]
RewriteRule ^(.+\.png)$ process.php?file=$1 [QSA,NC]
RewriteRule ^(.+\.png)$ http://other.website.com/$1
拼写模块在httpd.conf中已启用,.htaccess文件可以修改所有可能的设置,但其工作原理与以前相同,如果输入了具有不同大小写文件名的文件,则不会重定向。请尝试在Apache配置中使用
tolower
映射。首先,对于tolower
调用httpd.conf
(或apache2.conf
或VHost-config):
接下来,在条件检查中,将$1
转换为小写:
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/directory/${lc:$1} -f [NC]
RewriteRule ^(.+\.png)$ process.php?file=$1 [QSA,NC]
RewriteRule ^(.+\.png)$ http://other.website.com/$1
请注意,要使上述方法起作用,您的文件应始终使用较低的字母。这是一个好方法,但那里已经有大量文件,有些文件的名称可能有冲突(仅不同大小写)。我无法将它们全部转换为小写。
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/directory/${lc:$1} -f [NC]
RewriteRule ^(.+\.png)$ process.php?file=$1 [QSA,NC]
RewriteRule ^(.+\.png)$ http://other.website.com/$1