1

When permalink is set to plain everything works fine. but when I change permalink to post name only Wordpress home page(dev.site.com/blog) works fine, but for other pages(e.g., dev.site.com/blog/first-page) it will be redirected to dev.site.com.

server {
    listen 80;
    listen [::]:80;

    root /var/www/wordpress-site;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name dev.site.com www.dev.site.com;

    location = /favicon.ico { log_not_found off; access_log off; }
    location = /robots.txt { log_not_found off; access_log off; allow all; }

    location /blog {
            alias /var/www/wordpress-site/;
            try_files $uri $uri/ /blog/index.php?$args;

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

    # angular project

    location / {
            root /home/user/angular-project;
            try_files $uri $uri/ /index.html;
    }

    location ~ /\.ht { deny all; }
}

I tried changing try_files, but still doesn't work

Thank you :)

8
  • Are these sites using the same codebase and database? WP will redirect to the current canonical URL of a post to avoid duplication and SEO issues
    – Tom J Nowell
    Commented Apr 1, 2020 at 15:14
  • They are not using same codebase or database . / is angular project and /blog is wordpress
    – Mr.Bhat
    Commented Apr 1, 2020 at 15:48
  • I mean site.com vs dev.site.com, you said posts on dev.site.com redirect to site.com, can you edit your question to be clearer, e.g. use example full URLs
    – Tom J Nowell
    Commented Apr 1, 2020 at 16:44
  • When I change permalink to post name page is redirected to dev.site.com.
    – Mr.Bhat
    Commented Apr 1, 2020 at 18:48
  • Oh so all posts redirect to the root, is it a redirect, or are all the permalinks dev.site.com? What kind of redirect is it? This doesn't sound like an Apache issue, it sounds like something in PHP/WordPress is doing this. Disable all plugins and switch to the default theme
    – Tom J Nowell
    Commented Apr 1, 2020 at 21:08

1 Answer 1

0

Try separating the second location block:

location /blog { alias /var/www/wordpress-site/; try_files $uri $uri/ /blog/index.php?$args; }

location ~ \.php$ { fastcgi_split_path_info ^(/blog)(/.*)$; include snippets/fastcgi-php.conf; include fastcgi_params; fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $request_filename; }

Hope this helps!

3
  • Nope, moving php block gives 404 even for the homepage
    – Mr.Bhat
    Commented Apr 1, 2020 at 15:07
  • Did you add in fastcgi_split_path_info ^(/blog)(/.*)$; like above?
    – harvey
    Commented Apr 2, 2020 at 2:16
  • Yes, nothing happened :(
    – Mr.Bhat
    Commented Apr 2, 2020 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.