NGINX Rewrite Rule Issue - First Rule Should have Priority?

Here is my issue, I recently added:


rewrite ^/(.*)/$ /$1 permanent;

Basically, when sites link us and they add a final “/” themselves, we go to remove it automatically upon arrival.

However, I do have some folders that I want access to without having the need to put a direct file name. So I figured having rewrite rules before this rule would do the trick:


location ~ /admin/ {
index index.php;
rewrite ^/admin/ /admin/index.php;
}

rewrite ^/(.*)/$ /$1 permanent;


So i was thinking of forcing admin to rewrite to the exact index file before the slash removal kicks in, but that doesn’t work.

Any ideas?

Cheers!
Ryan