Не удается заставить ModRewrite работать под Ubuntu - PullRequest
0 голосов
/ 21 июня 2011

Понятия не имею, что я делаю не так с 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 не работает?

Ответы [ 2 ]

2 голосов
/ 13 декабря 2012

измените AllowOverride None на AllowOverride All и перезагрузите сервер.

2 голосов
/ 21 июня 2011

У вас есть AllowOverride None во всех соответствующих каталогах. Я считаю, что вам нужно AllowOverride FileInfo Options (как минимум) для соответствующего каталога, который в данном случае выглядит как /var/www.

Edit:

В случае, если неясно, я имею в виду конфигурацию вашего виртуального хоста, а не что-либо в .htaccess.

...