mod-rewrite - 在 Ubuntu 下根本无法让 ModRewrite 工作

标签 mod-rewrite ubuntu apache2

我不知道我在使用 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 设置不起作用?

最佳答案

你有 AllowOverride None在所有相关目录中。相信你需要AllowOverride FileInfo Options (至少)相关目录,在这种情况下似乎是 /var/www .

编辑:

如果不清楚,我指的是您的虚拟主机配置,而不是 .htaccess 中的任何内容。

关于mod-rewrite - 在 Ubuntu 下根本无法让 ModRewrite 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430011/

相关文章:

全局安装包的 Ubuntu 18.04 Yarn 二进制文件

php - 如果 Composer 在我的 Web 服务器根目录之外,如何包含它的自动加载?

apache - 如何验证 Apache 缓存是否正常工作?

Apache mod_rewrite : explain me %{HTTP_HOST} especially when using addon domains

apache - 将所有 url(包括无路径)重定向到子目录中的文件

apache - 使用 SSL 从非 www 重定向到 www

php - htaccess 404 在添加尾部斜杠时无法正常工作

ubuntu - Heroku登录无法打开浏览器

ruby-on-rails - 使用乘客运行 Rails 3.0 和 Rails 3.1 应用程序(使用不同的 rvm gemsets)

ubuntu - 网站太慢