Can't get ModRewrite to work at all under Ubuntu
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://loc开发者_开发问答alhost/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?
You have AllowOverride None
in all relevant directories. I believe you need AllowOverride 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.
change AllowOverride None
in AllowOverride All
and restart your server.
精彩评论