Answer the question
In order to leave comments, you need to log in
How to remove redirect from /blog to /blog/ (slash at the end) in wordpress using nginx?
There is a site where all requests to /blog are proxied by nginx to php-fpm.
Wordpress is unpacked in a separate directory. nginx config (section handling /blog requests):
location @wp {
rewrite ^/blog(.*) /blog/index.php?q=$1;
}
location /blog {
alias /var/www/blog;
index index.php;
try_files $uri $uri/ @wp;
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
access_log off;
log_not_found off;
expires 1M;
}
location ~ \.php$ {
if_modified_since off;
fastcgi_pass php-fpm;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_ignore_client_abort off;
fastcgi_pass_header Last-Modified;
}
}
Answer the question
In order to leave comments, you need to log in
Figured it out myself, maybe it will help someone:
1. In the nginx config, change:
To:
After that, both /blog and /blog/ will work - i.e. this removes the redirect on the nginx side.
BUT, it turns out there is another redirect in Wordpress, exactly the same, which can be turned off by entering in functions.php:
try_files $uri $uri/ @wp;
try_files $uri @wp;
remove_filter('template_redirect', 'redirect_canonical');
add_filter('redirect_canonical', 'homepage_disable_redirect_canonical');
function homepage_disable_redirect_canonical($redirectUrl) {
if(is_home()) {
$redirectUrl = false;
}
return $redirectUrl;
}
Hello!
Try here, these solutions -
https://serverfault.com/questions/597302/removing-...
Google
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question