.htaccess Riscrivi la sottodirectory di Wordpress senza rompere le altre sottodirectory
Quindi ho WordPress installato /wp/
ma voglio che tutti gli URL di WordPress vengano riscritti per apparire nella directory principale. Al momento ho questo lavoro (vedi sotto) ma voglio cambiare il mio in .htaccess
modo che non rompa altre sottodirectory.
Ad esempio, se voglio visitare www.example.com/images/image.png
, attualmente mi reindirizza a una pagina 404 su WordPress.
È anche possibile con .htaccess
?
Codice attuale:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
Aggiornamento : testato il suggerimento di MrWhite con la modalità di navigazione in incognito e un secondo browser. Nessun effetto. Nuovo .htaccess
file:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
Risposte
È necessario aggiungere una condizione per escludere i file esistenti, altrimenti una richiesta di /images/image.png
verrà naturalmente riscritta /wp/images/image.png
e attiverà un 404 in WordPress (a meno che /wp/images/image.png
non esistesse effettivamente).
Ad esempio, aggiungi la seguente condizione alla regola esistente:
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
AGGIORNAMENTO: questo non sembra funzionare. Va ancora alla pagina di WordPress 404
Hai messo la RewriteCond
direttiva nel posto sbagliato.
RewriteCond
le direttive non sono dichiarazioni del tutto separate, sono condizioni che si applicano alla RewriteRule
direttiva che segue. Di per sé, le RewriteCond
direttive non fanno nulla.
La RewriteCond
direttiva deve andare (ovunque) prima della RewriteRule
direttiva:
RewriteEngine on
#Wordpress
# Rewrites all URLS without wp in them
RewriteCond %{REQUEST_URI} !^/wp/
# Rewrites all URLS [Replace "example" with the actual domain, without the TLD (.com, .net, .biz, etc)]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.
# Request does not map to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite all those to insert /folder
RewriteRule ^(.*)$ /wp/$1 [L]
Inoltre, dai un'occhiata al .htaccess
file "WordPress" nella /wp
sottodirectory come riferimento. Questo fa lo stesso genere di cose.
A parte: a meno che tu non abbia più domini o sottodomini che non vuoi riscrivere, puoi rimuovere il controllo del nome host (cioè la RewriteCond
direttiva che controlla la HTTP_HOST
variabile del server).