Configure nginx for open the WP blog on subfolder

174 Views Asked by At

I have a project made using laravel. Site is multi-language. First segment of URL is language code but for default language I don't want to add language code.

Examples: mydomain.com/something and mydomain.com/fr/something

Now I have installed blog with WordPress which is multi-language too. Blog installed on blog.mydomain.com but I want to open it like this

mydomain.com/blog/slug and mydomain.com/fr/blog/slug

This is my part of my nginx config.

server {
listen 80;
server_name mydomain.com;

# Laravel project configuration
location / {
    root /home/forge/mydomain.com/public;
    try_files $uri $uri/ /index.php?$query_string;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

# WordPress blog configuration
location /blog {
    alias /home/forge/blog.mydomain.am/public;
    index index.php;
    try_files $uri $uri/ /blog/index.php?$args;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}

# Multilingual configuration for blog
location ~ ^/(?<lang>(en|fr))/blog {
    alias /home/forge/blog.mydomain.com/public/$lang;
    index index.php;
    try_files $uri $uri/ /blog/index.php?$args;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}

}

Please help me configure nginx. Current config doesn't work, it is always redirects to blog.mydomain.com/en/blog page.

0

There are 0 best solutions below