我在开发计算机上使用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