Wie richte ich WordPress in einem Laravel-Unterverzeichnis ein?
Posted: 11 Jan 2025, 09:35
Ich arbeite an einem Laravel-Projekt und muss ein WordPress-Projekt auf der /blog-Route einrichten. Ich habe der Nginx-Konfiguration bereits einen Serverblock hinzugefügt und die Regeln für die .htaccess-Datei aktualisiert, aber das WordPress-Projekt funktioniert nicht. Bitte lassen Sie mich wissen, wenn ich hier etwas verpasst habe. Vielen Dank.
Meine Nginx-Konfiguration ist:
und Meine .htacc-Datei befindet sich im öffentlichen Ordner:
Meine Nginx-Konfiguration ist:
Code: Select all
server {
listen 80;
server_name example.com www.example.com;
root /root/example/public;
index index.php;
# Ensure proper handling of Laravel requests
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ^~ /blog/ {
root /root/example/public/blog;
index index.php index.html;
try_files $uri $uri/ /index.php?$args;
}
# PHP-FPM configuration
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Deny access to .htaccess files (if any exist)
location ~ /\.ht {
deny all;
}
# Logs
error_log /var/log/nginx/laravel_error.log;
access_log /var/log/nginx/laravel_access.log;
}
Code: Select all
Options -MultiViews -Indexes
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteEngine On
RewriteBase /blog/
# Ensure WordPress works from the /blog directory
RewriteRule ^index\.php$ - [L]
# Rewrite all other requests to WordPress index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]