0

I have a Symfony application at mysite.com and a WordPress application at mysite.com/blog:

server {
    server_name mysite.com;
    root /var/www/mysite/symfony/web;

    location / {
        try_files $uri /app.php$is_args$args;
    }

    location ~ ^/app\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        internal;
    }

    location /blog {
        root /var/www/mysite/wordpress;
        rewrite ^/blog/(.+)$ /$1 break;
        try_files $uri $uri/ /blog/index.php$is_args$args;

        location ~ \.php {
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi_params;
            fastcgi_split_path_info ^(?:\/blog\/)(.+\.php)(.*);
            fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
        }
    }

    access_log /var/log/nginx/mysite.com-access.log;
    error_log /var/log/nginx/mysite.com-error.log;
}

When I access my blog route (mysite.com/blog), nginx 301 redirects to add a trailing slash (mysite.com/blog/). Is there any way I can avoid this redirect? I've noticed this doesn't happen with Symfony - mysite.com/admin works fine.

I've tried adding rewrite ^/(.*)/$ /$1;, but this just results in a redirect loop.

0

The trailing slash is added by WordPress. You can disable it by going to your WordPress Settings -> Permalinks, choose custom structure and remove the trailing slash.

  • Thanks for your response, but I believe this setting only refers to posts. I confirmed this by placing a die; at the top of WordPress' index.php - I still get redirected. – Jonathan Nov 7 '14 at 19:22
  • I see. Maybe you should have a look at tommcfarlin.com/trailing-slash-in-wordpress – rauberdaniel Nov 7 '14 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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