Help With Nginx Directives

Discussion in 'Installation/Configuration' started by parkerj, Mar 18, 2014.

  1. parkerj

    parkerj Member HowtoForge Supporter

    I am using a custom php framework that utilizes the following rewrite rules:

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

    In the Nginx Directive under the domain's option tab, I've tried adding

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

    and I've also tried adding

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

    and none of the options I've tried seem to work. I visit the site and it want to download instead of serve the index.php file. First, did I put them in the right place, and second, did I convert it correctly? Any help with this is greatly appreciated.
     
  2. falko

    falko Super Moderator ISPConfig Developer

    Try

    Code:
    location / {
      try_files $uri $uri/ /index.php?url=$request_uri&$args last;
    }
     
  3. parkerj

    parkerj Member HowtoForge Supporter

    Thanks Falko for responding. I've added it to the directives, but it is giving me a 404. Here are some examples of what the urls may look like and what works or doesn't work with the rewrite you suggested:

    http://example.com/dashboard/ => 404 Error
    http://example.com/profile/ => 404 Error
    http://example.com/index/logout/ => 404 Error
    http://example.com/course/?id=1&term=13/FA => 404 Error
    http://example.com/course/student/schedule/?term=13/FA => 404 Error

    If I add this to the directive:
    location / {
    try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
    rewrite ^/(.*)$ /index.php?url=$1;
    }

    I will get these results:
    http://example.com/dashboard/ => Error 500
    http://example.com/profile/ => Error 500
    http://example.com/index/logout/ => Error 500
    http://example.com/course/?id=1&term=13/FA => Works
    http://example.com/course/student/schedule/?term=13/FA => Works

    I am not that great at rewrite rules, so can you help me find a happy medium between our two rewrites? Thanks again for your help.
     
  4. parkerj

    parkerj Member HowtoForge Supporter

    Actually with one small change to my rewrite, it does work.
     

Share This Page