【问题标题】:Can't get ModRewrite to work at all under Ubuntu在 Ubuntu 下根本无法让 ModRewrite 工作
【发布时间】:2011-09-19 18:37:44
【问题描述】:

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

【问题讨论】:

    标签: mod-rewrite ubuntu apache2


    【解决方案1】:

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

    编辑:

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

    【讨论】:

    • 是的!非常感谢,伙计。此外,我不得不将第一次重写时的正则表达式更改为:RewriteRule ^showimage.jpg(.*) localhost/test/showimage.php$1。非常感谢。
    【解决方案2】:

    AllowOverride None 更改为AllowOverride All 并重新启动您的服务器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-05
      • 2012-06-15
      • 1970-01-01
      相关资源
      最近更新 更多