/ / Rimuovi ricorsivamente .php .htaccess & Wordpress - php, wordpress, apache, .htaccess

Rimuove in modo ricorsivo .php .htaccess e Wordpress - php, wordpress, apache, .htaccess

Ho creato un sito Wordpress. Devo rimuovere in modo ricorsivo l'estensione .php dai file in una cartella specifica.

Dire: www.domain.com/wordpresspage/ (istituito con permalink, tutto bene).

Devo quindi rimuovere ricorsivamente .php per la cartella: domain.com/gz/*

Il contenuto di domain.com/gz/ dovrebbe essere rimossa l'estensione .php. Ma solo per questa cartella.

Struttura delle cartelle

/
-/images (No .htaccess rules should apply, Wordpress takes care of it.)
-/downloads (No .htaccess rules should apply, Wordpress takes care of it.)
-/gz (.htaccess change, to remove .php file extension, overwriting Wordpress, in this particular folder)
-file1 (No .htaccess rules should apply, Wordpress takes care of it.)
-file2 (No .htaccess rules should apply, Wordpress takes care of it.)

Prima ho usato il seguente contenuto .htaccess per rimuovere le estensioni .php, ma ora devo forzarlo solo su una cartella, dal momento che Wordpress si occupa del resto.

#RewriteBase /
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^.]+).php HTTP
#RewriteRule ^([^.]+).php$ https://example.com/$1 [R=301,L]
#RewriteCond %{REQUEST_URI} !(.[^./]+)$
#RewriteCond %{REQUEST_fileNAME} !-d
#RewriteCond %{REQUEST_fileNAME} !-f
#RewriteRule (.*) $1.php [L]

Ho già provato un sacco di cose, ma le ultime incluse:

  1. Utilizzare il vecchio file .htaccess che rimuove .php su tutte le pagine. Questo risolve il problema del mio percorso, ma fornisce un errore interno del server sul resto del sito.
  2. Ho provato molti modi per filtrare quella cartella in modo ricorsivo, al punto che non sono più sicuro che sia possibile. (Non ricordare nemmeno una frazione di quello che ho provato).
  3. Ho provato nei permalink per aggiungere .php, ma dal momento che reindirizzerà per rimuoverlo di nuovo, visualizzerò un altro errore interno del server.

TL; DR - Posso rimuovere ricorsivamente .php su un percorso specifico nel mio file .htaccess, quindi Wordpress ignora questa cartella e lascia che si occupi della propria attività?

Aggiunto dopo il primo round di aiuto, il mio file .htaccess ora appare così:

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

RewriteEngine On
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*).php$ /$1 [R=301,L]

# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]

<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>

AddType application/x-httpd-php-old .php

<IfModule security_module>
SecFilterEngine Off
</IfModule>
<IfModule security2_module>
SecRuleRemoveByID 1-99999
SecRuleRemoveByTag unoeuro
</IfModule>

Dopo la riapplicazione permalink, Wordpress aggiunge questa sezione al file .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Grazie in anticipo,

L

risposte:

2 per risposta № 1

Quello che potresti fare è il seguente

RewriteEngine On
# Only apply if no rewrite
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*).php$ /$1 [R=301,L]

# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]

Quindi se richiedi ad es. /gz/gz5.php è verrà reindirizzato a / gz / gz5 e se la richiesta è / gz / gz5 verrà ricomposta su /gz/gz5.php