I’m working on a Laravel project and must set up a WordPress project at the /blog route. I already added a server block on the Nginx Configuration and updated the .htaccess file rules but the WordPress project isn’t working. Please let me know if I anything missed here. Thank you.
My Nginx configuration is:
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;
}
and My .htacc file is on the public folder is:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
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]
</IfModule>
<IfModule mod_rewrite.c>
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]
</IfModule>