在CentOS 7上的Apache 2.4,在cPanel / WHM远程服务器上。
我想在找不到.jpg文件时获取Apache服务器的404响应,而不是重写到index.php,它会加载整个网络应用程序。
尝试在.htaccess
。
#Trying to exclude jpegs:
RewriteCond %{REQUEST_URI} !\.jpg$
#And exclude these folders:
RewriteCond %{REQUEST_URI} !^/(folder1|folder2)/
#And rewrite everything else (commenting this results in regular Apache 404 responses for missing image files):
RewriteRule .* index.php [L]
当我尝试加载导致404
,example.com/asdf.jpg
或example.com/folder1/abc.css
的这些网址时,RewriteRule
仍然生效,它们会被重写为{{1 <},并且加载了CMS index.php
页面。
当我对404
发表评论时,这两个网址会产生轻量级的Apache RewriteRule
响应,而不是CMS 404
响应。
完成404
的{{1}}部分:
mod_rewrite
编辑 - 这是.htaccess
配置:
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(folder1|folder2)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
## test excluding .jpg from rewrite
RewriteCond %{REQUEST_URI} !(\.jpg)$
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
</IfModule>
编辑,我确实重写了VirtualHost
。它会显示正在应用<VirtualHost 12.34.56.7:80>
ServerName site.example.com
ServerAlias www.site.example.com
DocumentRoot /home/someuser/public_html
ServerAdmin webmaster@site.example.com
UseCanonicalName Off
CustomLog /etc/apache2/logs/domlogs/site.example.com combined
<IfModule log_config_module>
<IfModule logio_module>
CustomLog /etc/apache2/logs/domlogs/site.example.com-bytes_log "%{%
s}t %I .\n%{%s}t %O ."
</IfModule>
</IfModule>
## User someuser # Needed for Cpanel::ApacheConf
<IfModule userdir_module>
<IfModule !mpm_itk.c>
<IfModule !ruid2_module>
UserDir enabled someuser
</IfModule>
</IfModule>
</IfModule>
# Enable backwards compatible Server Side Include expression parser for Apache
versions >= 2.4.
# To selectively use the newer Apache 2.4 expression parser, disable SSILegacy
ExprParser in
# the user's .htaccess file. For more information, please read:
# http://httpd.apache.org/docs/2.4/mod/mod_include.html#ssilegacyexprparser
<IfModule include_module>
<Directory "/home/someuser/public_html">
SSILegacyExprParser On
</Directory>
</IfModule>
<IfModule suphp_module>
suPHP_UserGroup someuser someuser
</IfModule>
<IfModule suexec_module>
<IfModule !mod_ruid2.c>
SuexecUserGroup someuser someuser
</IfModule>
</IfModule>
<IfModule ruid2_module>
RMode config
RUidGid someuser someuser
</IfModule>
<IfModule mpm_itk.c>
# For more information on MPM ITK, please read:
# http://mpm-itk.sesse.net/
AssignUserID someuser someuser
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ /home/someuser/public_html/cgi-bin/
</IfModule>
# To customize this VirtualHost use an include file at the following location
# Include "/etc/apache2/conf.d/userdata/std/2_4/someuser/csite.example.com/*.conf"
</VirtualHost>
规则,即使trace6
不应该应用规则。我在虚拟机测试服务器上尝试了这个,它在那里工作,但不在这个物理远程服务器上。
以下是跟踪的前13行:
.*
答案 0 :(得分:1)
在寻找匹配的ErrorDocument
时,听起来您的规则正在捕获子请求。尝试在您的规则中添加NS
标记。