在我的服务器上,我正在运行awstats,这是一个我目前可以通过以下 URL 访问的脚本:
我正在尝试使用重写规则,以便我可以使用
这是我为重写规则定义的
RewriteRule ^(.*)$ bin/awstats.pl/?config=$1 [NC,L]
httpd 虚拟主机
# Address
ServerName stats.example.com
# Rewrite
RewriteRule ^(.*)$ bin/awstats.pl/?config=$1 [NC,L]
Options ExecCGI
AddHandler cgi-script .cgi .pl
Alias /awstatsstuff "/path/to/awstatsstuff/"
<Directory "/path/to/awstatsstuff">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
</Directory>
问题是我尝试访问的任何内容(除了索引)都会给我一个 400,并且我的 apache 日志显示没有错误。
如果此规则正常工作,我是否有不同的配置问题?还是我错过了什么?是的,RewriteEngine
开着。
编辑
根据 Michael Berkowski 的评论,我确定这实际上是资源也被定向到 pl 脚本的问题,我已经修改并正在使用以下内容:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/([0-9a-z]+\.[0-9a-z]+\.[0-9a-z]+)$ bin/awstats.pl/?config=$1 [NC,L]
我现在可以使用再次加载页面
https://stats.example.com/bin/awstats.pl/?config=www.example.com
这意味着可以正确加载所有资源,但是
将返回 400 (这不是来自 pl 脚本,如果找不到指定的配置文件,它将返回 200 和错误消息,同样,日志中没有错误消息。
另一个编辑
在更改[NC,L]
为 时[R=302]
,我会根据要求提供正确的重定向,
curl -k "https://stats.example.com/a.b.c"
...
<p>The document has moved <a href="https://stats.example.com/bin/awstats.pl/?config=a.b.c">here</a>.</p>
...
使用[R=403]
证明重写规则按预期工作
我现在面临的问题是,在使用时[NC,L]
,我仍然收到一个400
,httpd 日志中没有可用的错误。