Roland Kliem: Verständnisfrage zu mod_rewrite

Hallo!

Ich habe da ein kleine Frage bezüglich mod_rewrite:

Mein DocuementRoot ist /srv/www/htdocs
Darin befindet sich ein Verzeichnis namens rewrite, also /srv/www/htdocs/rewrite, das wiederum drei Dateien enthält:

  • .htaccess
  • old.html
  • new.html

Die .htaccess hat folgenden Inhalt

Options +Indexes +FollowSymLinks
RewriteEngine On
RewriteRule ^new.html$ old.html

D.h. er soll alle Anfragen von new.html nach old.html umleiten. Das funktioniert auch soweit (die Adressleiste zeigt http://localhost/rewrite/new.html an und ich bekomme den Inhalt von old.html), aber wenn ich das [R]-Flag ergänze macht er nicht das, was er soll:

Options +Indexes +FollowSymLinks
RewriteEngine On
RewriteRule ^new.html$ old.html [R]

In der Adressleiste steht dann http://localhost/srv/www/htdocs/rewrite/old.html anstatt http://localhost/rewrite/old.html

Wie kann das sein, muss ja irgendwas mit absoluten/relativen Angaben zu tun haben, oder?

Grüße,

Roland

  1. Hi!

    Options +Indexes +FollowSymLinks
    RewriteEngine On
    RewriteRule ^new.html$ old.html [R]

    In der Adressleiste steht dann http://localhost/srv/www/htdocs/rewrite/old.html anstatt http://localhost/rewrite/old.html

    Wie kann das sein, muss ja irgendwas mit absoluten/relativen Angaben zu tun haben, oder?

    Siehe Doku: http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html#redirect

    Note: When you use this flag, make sure that the
    substitution field is a valid URL! If not, you are
    redirecting to an invalid location! And remember that
    this flag itself only prefixes the URL with
    http://thishost[:thisport]/, rewriting continues.
    Usually you also want to stop and do the redirection
    immediately. To stop the rewriting you also have to
    provide the 'L' flag.

    Grüße
    Andreas

    --
    SELFHTML Linkverzeichnis: http://aktuell.de.selfhtml.org/links/
    1. Hallo Andreas!

      Siehe Doku: http://httpd.apache.org/docs-2.0/mod/mod_rewrite.html#redirect

      Habe ich bereits gelesen, aber ehrlich gesagt nicht so recht verstanden.

      Note: When you use this flag, make sure that the
      substitution field is a valid URL! If not, you are
      redirecting to an invalid location! And remember that
      this flag itself only prefixes the URL with
      http://thishost[:thisport]/, rewriting continues.
      Usually you also want to stop and do the redirection
      immediately. To stop the rewriting you also have to
      provide the 'L' flag.

      Heißt das also mit der "valid URL", dass die RewriteRule so aussehen muss:

      RewriteRule ^new.html$ http://localhost/rewrite/old.html [R]
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      So funktionierts, das würde schon mal gut sein. Kennst du ein gutes Tutorial zu mod_rewrite, das auch auf die Basics eingeht? z.B. habe ich gerade herausgefunden, dass es auch mit der zusätzlichen Angabe

      RewriteBase /rewrite

      funktioniert. Aber warum ist das so?