2016-08-16 2 views
0

Ich habe eine Website mit .htaccess, um Regeln neu zu schreiben, aber soem funktioniert nicht.Linux Mint - Apache 2.4 .htaccess rewriteRule funktioniert nicht

Dies ist meine .htaccess-Datei:

RewriteEngine On 
RewriteBase/
# Inicio 
RewriteRule ^inicio|home|index$ index.php [QSA,L] 

# Paginacion amigable 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)\.([0-9]+)$ $1?pag=$2 [QSA,L] 

# Miniaturas 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*\/)?tdd([A-Za-z0-9_~-]*)\/(.*)$ imagen.php?param=$2&src=$1$3 [QSA,L] 

#paginas 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*-p([0-9]+)$ interna.php?id=$1 [QSA] 

#Intranet 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*-i([0-9]+)$ intranet.php?id=$1 [QSA] 

#publicaciones 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*-n([0-9]+)$ publicaciones_detalle.php?id=$1 [QSA] 

# Paginas sin extension 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ $1.php [QSA] 

# sitemap 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule sitemap.xml sitemap.php [QSA] 

# Buscador 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^search$ buscar.php [QSA] 



# En caso de no existencia 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^.*$ 404.php [QSA] 

# Paginas incluidas en el template 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} ^.*\.php$ 
RewriteRule ^(.*)$ plantilla.php?uri=$1 [QSA] 

Aber ich habe einen Fehler zum Beispiel, wenn ich www.domain.com/contacto Zugriff auf sie wirft mir diesen Fehler:

Not Found 

The requested URL /contacto was not found on this server. 

Aber Wenn ich die URL wie folgt ändere, funktioniert www.domain.com/contacto.php.

Ich denke, diese Regel aus der unteren Liste sollte die Arbeit tun, nicht wahr?

# Paginas sin extension 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.+)$ $1.php [QSA] 

Warum mache ich falsch?

Dies sind alle für meine Apache geladenen Module:

Loaded Modules: 
core_module (static) 
so_module (static) 
watchdog_module (static) 
http_module (static) 
log_config_module (static) 
logio_module (static) 
version_module (static) 
unixd_module (static) 
access_compat_module (shared) 
alias_module (shared) 
auth_basic_module (shared) 
authn_core_module (shared) 
authn_file_module (shared) 
authz_core_module (shared) 
authz_host_module (shared) 
authz_user_module (shared) 
autoindex_module (shared) 
deflate_module (shared) 
dir_module (shared) 
env_module (shared) 
filter_module (shared) 
mime_module (shared) 
mpm_prefork_module (shared) 
negotiation_module (shared) 
php7_module (shared) 
rewrite_module (shared) 
setenvif_module (shared) 
status_module (shared) 

Und das ist meine domain.dev.conf Datei auf/etc/apache2/sites-enabled:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /var/www/html/domain/ 
    ServerAlias www.domain.dev 
    ServerName domain.dev 
    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
    <Directory /var/www/html/domain> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
       RewriteEngine On 
    </Directory> 
</VirtualHost> 

Es war funktioniert gut auf Apache 2.2, aber nach dem Upgrade auf 2,4 funktioniert nicht mehr.

Gibt es einen Unterschied zwischen Apache 2 und 2,4 in Form .htaccess-Dateien der Anwendung

Danke

+0

Was ist der Zweck des Regelblocks 'plantilla.php'? Das besagt, dass, wenn Sie '/ foo' und'/foo' anfordern und der Dateiname der Anfrage '/.*. Php' ist, dann schreiben Sie in' plantilla.php' um - es macht keinen Sinn. –

+0

Plantilla.php ist wie eine Vorlage. Alle anderen Seiten sind Echo in dieser Datei – juanpscotto

Antwort

0

diese Regel hinzufügen Pflege der .php zu nehmen.

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L] 
+0

Nop. Es funktioniert nicht. – juanpscotto

0

Ändern Sie diesen Block:

# Paginas sin extension 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.+)$ $1.php [QSA] 

dazu:

# Paginas sin extension 
# (if exists) 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [QSA,L] 

Für die Zwecke der Erweiterung und der DRY principle haftet, Ihre gesamte .htaccess-Datei mit dem folgenden Code ersetzen stattdessen:

RewriteEngine On 
RewriteBase/

# Ignorar archivos y directorios 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule^- [END] 

# Inicio 
RewriteRule ^inicio|home|index$ index.php [QSA,L] 

# Paginacion amigable 
RewriteRule ^(.+).(\d+)$ $1?pag=$2 [QSA,L] 

# Miniaturas 
RewriteRule ^(.*/)?tdd([A-Za-z0-9_~-]*)/(.*)$ imagen.php?param=$2&src=$1$3 [QSA,L] 

# paginas 
RewriteRule ^.*-p(\d+)$ interna.php?id=$1 [QSA,L] 

# Intranet 
RewriteRule ^.*-i(\d+)$ intranet.php?id=$1 [QSA,L] 

# Publicaciones 
RewriteRule ^.*-n(\d+)$ publicaciones_detalle.php?id=$1 [QSA,L] 

# sitemap 
RewriteRule ^sitemap.xml$ sitemap.php [QSA,L] 

# Buscador 
RewriteRule ^search$ buscar.php [QSA,L] 

# Paginas incluidas en el template 
# RewriteCond %{REQUEST_FILENAME} -f 
# RewriteCond %{REQUEST_FILENAME} ^.*\.php$ 
# RewriteRule ^(.*)$ plantilla.php?uri=$1 [QSA] 

# Paginas sin extension 
# (En caso de existencia) 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [QSA,L] 

# En caso de no existencia 
RewriteRule ^.*$ 404.php [QSA] 

Dort habe ich alle Duplicate-Verweise auf Bedingungen entfernt, die prüfen, ob die Anfrage mit einer vorhandenen Datei oder einem vorhandenen Ordner übereinstimmt - Sie müssen dies nur einmal tun und dann das Neuschreiben stoppen, wenn es übereinstimmt. Ich würde empfehlen, es aus Sicherheitsgründen für Verzeichnisse zu deaktivieren (indem Zeile 6: RewriteCond %{REQUEST_FILENAME} -d entfernt wird).

Wie Sie sehen können, habe ich diesen Block auskommentiert, der in meinem Kommentar zu Ihrer ursprünglichen Frage erwähnt wurde, da er offenbar keine bestimmte Funktion hat - Sie müssen das beheben, um es zum Laufen zu bringen.

+0

Hallo, danke für die Antwort. Ich habe das versucht, aber ich bekomme einen Fehler 404 an erster Stelle. Ich verstehe es nicht auf Apache 2.2 Es hat gut funktioniert. Jetzt habe ich auf 2.4 aktualisiert und funktioniert nicht mehr – juanpscotto

Verwandte Themen