Joomla at nginx - remove slashes doesn't work properly
I'm running joomla 3.7.3 using nginx 1.10.3 and I've a problem with removing trailing slashes. I've "search engine friendly URLs" turned on, as well as "Use URL rewriting".
I've these stuff in my nginx conf file:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/folder;
index index.php index.html index.htm default.html default.htm;
rewrite ^/(.+)/$ /$1 permanent;
server_name 000.000.00.000;
server_name_in_redirect off;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
And it's working, but partially. URLs like:
http://000.000.00.000/category/ sure became http://000.000.00.000/category
but when I try to access http://000.000.00.000/administrator/ it's now inaccessible, and Chrome says ERR_TOO_MANY_REDIRECTS
I can't figure how to fix this, I've also tried to replace:
location / {
try_files $uri $uri/ /index.php?$args;
}
with this:
location / {
try_files $uri /index.php?$args;
}
But then when I try to access http://000.000.00.000/administrator/ the server redirects me back to my home page http://000.000.00.000/
Please help me to figure this out.
Solution 1:
Currently the rewrite
happens before and regardless of the try_files
inside location
.
You could try to put it inside a location, after testing static files, e.g.
location / {
try_files $uri $uri/ @joomlaurls;
}
location @joomlaurls {
rewrite ^/(.+)/$ /$1 permanent;
try_files $uri $uri/ /index.php?$args;
error_page 404 = /index.php;
}
Solution 2:
Very late to the party but after looking for solutions for hours and hours, I seem to have fixed this issue by adding a simple "~" in front of the "/".
#Joomla public frontend application
location ~ / {
try_files $uri $uri/ /index.php?$args;
}
now it doesn't matter if I have a trailing slash in my SEF url or not.