我在我的开发机器上使用 mod_rewrite 设置 Apache 时遇到问题。Mod_rewrite 处于活动状态,并且适用于某些规则。某些规则无法按预期工作,例如:
RewriteRule ^static/([^/]+)/([^/]+) /static.php?sISOCode=$1&sPage=$2
在 static.php 我这样做(用于调试):
<?php
print_r($_GET); print_r($_POST); print_r($_SERVER); die();
哪个打印(从 $_SERVER 数组中删除了一些项目):
Array
(
)
Array
(
)
Array
(
[SERVER_SIGNATURE] => <address>Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch Server at alpha.prove.no Port 80</address>
[SERVER_SOFTWARE] => Apache/2.2.11 (Ubuntu) PHP/5.2.6-3ubuntu4.1 with Suhosin-Patch
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /home/veg/workspace/project
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /home/veg/workspace/project/static.php
[REMOTE_PORT] => 38954
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /static/no/startCar
[SCRIPT_NAME] => /static.php
[PATH_INFO] => /no/startCar
[PATH_TRANSLATED] => redirect:/index.php/startCar
[PHP_SELF] => /static.php/no/startCar
[argv] => Array
(
)
[argc] => 0
)
不知何故,根据规则设置的 GET 参数没有通过。相同的 .htaccess 文件正在其他设置中使用,并且运行良好。此虚拟域的 Apache 配置:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName project.example.com
DocumentRoot /home/veg/workspace/project
<Directory /home/veg/workspace/project>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
发生这种情况时,访问日志和错误日志不会输出任何内容。任何想法表示赞赏。
适用于同一文件的规则示例:
RewriteRule ^faq/?$ /static.php?sISOCode=no&sPage=faq