Monday 2014-12-22

Say you want to port Gallery (the php app) from apache to nginx... and people have been creating galleries with spaces in their filenames.

Is this really the best way to handle the conversion?

location / {
  index index.php;
  # elementary teachers love filenames w spaces
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4%20$5%20$6%20$7%20$8%20$9;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4%20$5%20$6%20$7%20$8;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4%20$5%20$6%20$7;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4%20$5%20$6;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4%20$5;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3%20$4;
  }
  if ($request_uri ~ /(.*)\+(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2%20$3;
  }
  if ($request_uri ~ /(.*)\+(.*)/) {
    return 301 http://gallery.ofs.edu.sg/$1%20$2;
  }
  if (!-e $request_filename) {
    rewrite ^/(.*)?(.*) /main.php?g2_path=$1&$2 last;
  }
}