News for hackers. Stuff that matters.
Re:Nginx 1.6.0 stable released by eggnet on Thursday April 24, 2014 @11:49AM (#7641017)
You didn't really specify what you meant by clean URLs but, maybe this will be helpful to you or someone else.

I have a static site served via nginx, but I don't like seeing .html in the URLs.

It's a little tricky serving a static site without the .html extension because you may have a directory and an html page with the same name.

The way to deal with that is to actually use the .html extension in the file system but not URLs.

  location / {
    if ($uri ~ ^/google) {
      break;
    }
    if ($uri ~ ^/y_key_) {
      break;
    }
    if ($uri ~ \.html$) {
      return 404;
    }
    if ($uri = /index) {
      return 404;
    }
    if (!-f $request_filename) {
      rewrite ^/$ /index.html break;
      rewrite .* $uri.html break;
    }
  }
Re:Nginx 1.6.0 stable released by Spittie on Thursday April 24, 2014 @12:42PM (#7641358)
By the way, the nginx wiki says that you should avoid ifs when possible: http://wiki.nginx.org/IfIsEvil

Wouldn't something like this accomplish the same thing? (Sorry if I'm totally wrong, I'm not really good)

   location /google/ {

   }
   location /y_key_/ {

   }
   location ~ \.html$ {
      return 404;
   }
   location = /index {
      return 404;
   }
   location / {
      try_files $uri @rewrite
   }
   location @rewrite {
      rewrite ^/$ /index.html break;
      rewrite .* $uri.html break;
   }
Re:Nginx 1.6.0 stable released by marshallford on Thursday April 24, 2014 @12:45PM (#7641385)
This is yet another concern of mine. Most of my solutions involve at least 3 if statements. But I need them in order to check if a requested url is a directory or a file and such.
Re:Nginx 1.6.0 stable released by sondr3 on Thursday April 24, 2014 @10:35PM (#7644443)
What kind of app are you running that requires you to do something like this for clean URLs?
Re:Nginx 1.6.0 stable released by eggnet on Thursday April 24, 2014 @01:20PM (#7641593)
Thanks, I will try this, it looks like it will work.
Re:Nginx 1.6.0 stable released by eggnet on Friday April 25, 2014 @02:00PM (#7648055)
It does work, thanks!
Re:Nginx 1.6.0 stable released by manacit on Thursday April 24, 2014 @12:47PM (#7641396)
I don't mean to be blunt, but using if is not the way: http://wiki.nginx.org/IfIsEvil

Writing clean URLs is much easier with try_files, which allows you to do something like

    try_files $uri.html
If you don't want to see file extensions.