location /admin { error_page 403 = @deny; // Return forbidden and redirect allow 127.0.0.1; allow 192.168.0.1; deny all; try_files $uri $uri/ /index.php?$query_string; // Important for PHP rewrite cond ej (index.php/admin) } location @deny { return 301 http://example.com; // The redirect URL }