[FIXED] funktionierende .htaccess-Konfigurationen funktionieren nicht auf httpd.conf

Ausgabe

Eine frühe Warnung – ich bin ein Anfänger in der Back-End-Programmierung und im Moment war selbst das Umschreiben von .htaccess-URLs ein großer Schmerz bei der Implementierung.

Ich habe XAMPP Apache auf meinem Mac (nicht XAMPP-VM) mit einem Website-Ordner namens „Project“ in „/htdocs“ installiert. Im Grunde sieht eine Website, die ich mit URL übe, so aus – “localhost/Project”.

Es gab eine .htaccess-Datei in meinem “root”-Ordner (“root” ist der “/Project”-Ordner) und eine weitere in einem “PHP”-Ordner (dh root/PHP/.htaccess). Roots .htaccess hatte die folgenden Konfigurationen:

Options -Indexes

ErrorDocument 403 /Project/index.php

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !(.*)Pages 
        RewriteRule ^(.*)$ Pages/$1.php [L,NC]
</IfModule>

Während die .htaccess-Datei von root/PHP Folgendes hatte:

Deny from all

Alles hat funktioniert und nachdem ich ein bisschen mehr über Best Practices für .htaccess gelesen hatte, wollte ich alle oben genannten Konfigurationen nach httpd.conf verschieben, insbesondere die in “/Applications/XAMPP/xamppfiles/apache2/conf”. Ich habe den Code auf diesen httpd verschoben (richtig?), alles in den zuvor erwähnten .htaccess-Dateien auskommentiert, und so sieht der httpd jetzt darin aus:

Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
    Options -Indexes

    ErrorDocument 403 /Project/index.php
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !(.*)Pages 
        RewriteRule ^/(.*)$ /Pages/$1.php [L,NC]
    </IfModule>
</Directory>
    
<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
    Deny from all
</Directory>

Und es funktioniert nicht. Ich habe eine Weile versucht, eine Lösung zu googeln, und bisher absolut nichts. Für alle Fälle erwähne ich auch, dass das Ziel dieses „CMS“-Projekts darin besteht, „einmal schreiben, überall installieren“.

[BEARBEITEN]
Mit einigen Klarstellungen von @MrWhite sehen die Konfigurationen in so aus
xamppfiles. Auch Options -Indexesund /Project/PHP > Require all deniedfunktionieren nicht, da ich Ordner durchsuchen und über den Browser auf den Ordner “PHP” zugreifen kann. Und es hat auch vor diesem EDIT nicht funktioniert .

-xamppfiles/apache2/conf/httpd.conf

Alias /bitnami/ "/Applications/XAMPP/xamppfiles/apache2/htdocs/"
Alias /bitnami "/Applications/XAMPP/xamppfiles/apache2/htdocs"

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

Include "/Applications/XAMPP/xamppfiles/apache2/conf/httpd.conf"

-xamppfiles/apache2/conf/project.conf

<VirtualHost *:80>
    DocumentRoot "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
    
    Options -Indexes
        
    ErrorDocument 403 /Project/index.php
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} !(.*)Pages 
        RewriteRule ^(.*)$ Pages/$1.php [L,NC]
    </IfModule>
    
    <Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project/PHP">
        Require all denied
    </Directory>
</VirtualHost>

Ich würde jede Hilfe sehr schätzen.

Lösung

Ich habe das Problem gefunden, das war mein blinder Fehler.

<Directory "/Applications/XAMPP/xamppfiles/apache2/htdocs/Project">
    Options -Indexes
    //...

Ich habe auf den falschen htdocsOrdner gezeigt, der mein Projekt enthält, und der richtige Weg war:

<Directory "/Applications/XAMPP/xamppfiles/htdocs/Project">

Ich hoffe, das spart etwas Zeit für alle anderen, die darauf stoßen würden.


Beantwortet von –
Alex


Antwort geprüft von –
Dawn Plyler (FixError Volunteer)

0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like