我不知道我在使用ModRewrite做错了什么。 rewrite.load和proxy.load已加载a2enmod,两者都出现在启用的模块下。我尝试设置我能想到的最基本的ModRewrite场景,但它根本没有重定向,如果它们甚至没有被启用,我仍会得到相同的404错误消息。
这是我的目录的样子
/var/www
/test
showimage.php //showimage.jpg should redirect here
test.html //a page with a <img> tag that points to showimage.jpg
.htaccess //I've tried putting this in /var/www but it doesn't work either
这是我的.htaccess
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /var/www/test
RewriteRule ^showimage.jpg?(.*) http://localhost/test/showimage.php?$1
RewriteRule ^test.jpg http://localhost/test/showimage.php
这是test.html
<html>
<body>
<img alt="didn't work" src="showimage.jpg?thing=thing1" />
</body>
</html>
这是showimage.php
<?php
header('Content-Type: image/jpeg');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
if(isset($_GET["thing"])) {
$text = $_GET["thing"];
}
else {
$text = "none set by GET params";
}
$font = "some.ttf";
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagejpeg($im);
imagedestroy($im);
?>
最后,这是我目前在apache上启用的唯一网站:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
有人知道为什么modrewrite的这个设置不起作用吗?
答案 0 :(得分:2)
您在所有相关目录中都有AllowOverride None
。我相信您需要AllowOverride FileInfo Options
(至少)相关目录,在这种情况下似乎是/var/www
。
修改强>
如果不清楚,我指的是你的虚拟主机配置,而不是.htaccess中的任何内容。
答案 1 :(得分:2)
更改AllowOverride None
中的AllowOverride All
并重新启动您的服务器。