在 Ubuntu 下根本无法让 ModRewrite 工作
我不知道 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 设置不起作用吗?
I have no idea what I'm doing wrong with ModRewrite. rewrite.load and proxy.load have been loaded with a2enmod and both appear under modules enabled. I tried to set up the most basic ModRewrite scenario I could think of but it doesn't redirect at all, I still get the same 404 error messages had they not even been enabled.
Here's what my directory looks like
/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
Here's my .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
Here's test.html
<html>
<body>
<img alt="didn't work" src="showimage.jpg?thing=thing1" />
</body>
</html>
Here's 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);
?>
Finally, here's my only currently enabled site on 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>
Does anybody know why this setup for a modrewrite isn't working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
所有相关目录中都有
AllowOverride None
。我相信您需要相关目录的AllowOverride FileInfo Options
(至少),在本例中似乎是/var/www
。编辑:
如果不清楚,我指的是您的虚拟主机配置,而不是 .htaccess 中的任何内容。
You have
AllowOverride None
in all relevant directories. I believe you needAllowOverride FileInfo Options
(at a minimum) for the relevant directory, which in this case appears to be/var/www
.Edit:
In case it wasn't clear, I'm referring to your virtual host configuration, not anything in .htaccess.
更改
AllowOverride All
中的AllowOverride None
并重新启动服务器。change
AllowOverride None
inAllowOverride All
and restart your server.