0

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.

Mike
  • 85
  • 1
  • 6

2 Answers2

1

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.

Roderfault
  • 11
  • 1
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;
    }
Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Thank you for you answer, but when I try to run using this config I've an error: nginx: [emerg] invalid number of arguments in "try_files" directive. – Mike Jul 16 '17 at 19:33
  • After your recent update, every page now respond with error 404. – Mike Jul 16 '17 at 19:44
  • It seems to be working this way try_files /index.php?$args = /index.php?$args;. Does it makes any sense? Don't I have 404 error page at all anymore? Cause once I try to visit non-existing page I got redirect to the home page. – Mike Jul 16 '17 at 20:05
  • The last parameter should be `/index.php?$args`. There actually should be nothing wrong with using the standard SEO `try_files` again. Also added `404` handling example. – Esa Jokinen Jul 17 '17 at 14:33
  • Thank you for your help Esa! It's working. Could you please explain newbie me, if I need error_page 404 inside the location {} if I already have one outside? – Mike Jul 17 '17 at 18:11
  • The `try_files` causes the usage of the other location, so it should be enough this way. – Esa Jokinen Jul 17 '17 at 18:46