Converting Rewrites to Nginx

I have been trying to convert the following htaccess rules to nginx with

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

I’ve tried:

location / {
if (!-e $request_filename){
rewrite ^(.+)$ /index.php?url=$1 last;

and I’ve also tried:

location / {
try_files $uri $uri/ /index.php?url=$1 last;

None seem to work. Any help with this is greatly appreciated.

Posted at Nginx Forum:,248446,248446#msg-248446

location / {
try_files $uri $uri/ /index.php?url=$1 last;

Maybe what you want here is:
location / {
try_files $uri $uri/ @rewrite;
location @rewrite {
rewrite ^/(.*)$ /index.php/$1;

Thanks for pointing me in the right direction. That last part gave me a
redirect loop error, so I changed it to this:

rewrite ^/(.*)$ /index.php?url=$1;

I applied it, loaded the site, restarted nginx, and loaded the site
It seems to work. Hopefully, my change is not just a fluke but will
to work. However, if you think my change will cause an issue for the
future, please let me know. Again, thanks for your help.

Posted at Nginx Forum:,248446,248456#msg-248456

Ugh, I spoke too soon. It works when the urls are like this:

But it does not work when the urls are like this:

Sometime it brings back 404 Not Found and other times it comes back with
Internal Error

@Miguel, trying it my way and trying it the way you suggested, both give
a 404/500. Do you have any suggestions? Thanks.

Posted at Nginx Forum:,248446,248485#msg-248485

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs