views:

329

answers:

1

I'm trying to migrate a working ExpressionEngine installation from an Apache environment over to an NginX environment on a different box. I have come across a problem trying to convert some .htaccess rewrites to NginX.

The site uses the multi language module so needs a custom rewrite rule for every additional language.

This is my standard vhost config which seems to get ExpressionEngine working nicely (without the multi language module):

server {
  listen        80;
  server_name   domain.co.uk www.domain.co.uk;
  root          /var/www/vhosts/domain.co.uk/http;

  # Redirects non-www to www
  if ($host = 'domain.co.uk') {
    rewrite ^/(.*) http://www.domain.co.uk/$1 permanent;
  }

  access_log    /var/www/vhosts/domain.co.uk/log/access.log;
  error_log     /var/www/vhosts/domain.co.uk/log/error.log;

  location / {
    index       index.html index.htm index.php;
    # Removes index.php from URLs
    if (!-e $request_filename) {
      rewrite ^/(.*)$ /index.php/$1 last;
    }
  }

  # Standard pass for all PHP files
  location ~ \.php$ {
    include       fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME /var/www/vhosts/domain.co.uk/http$fastcgi_script_name;
  }

  # This is where all the ExpressionEngine magic happens
  location ~ \.php($|/) {
    include       fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;

    set           $script $uri;
    set           $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
      set         $script $1;
      set         $path_info $2;
    }

    fastcgi_param SCRIPT_FILENAME /var/www/vhosts/domain.co.uk/http$script;
    fastcgi_param SCRIPT_NAME $script;
    fastcgi_param PATH_INFO $path_info;
  }
}

The above seems to work nicely and does what I want it to. The Multi Language Module documentation is based on an Apache setup. For each additional language it requires a directory with it's own htaccess rewrite rule - a little like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.uk$
RewriteRule (.*) http://www.domain.co.uk/ar/$1 [R=301,L]

# Remove index.php
RewriteCond $1 !^(index\.php) [NC]
RewriteRule ^(.*)$ /de/index.php/$1 [L]

I have recreated the above rule by adding:

location /de {
  index     index.php;
  if (!-e $request_filename) {
    rewrite ^/(.*)$ /de/index.php/$1 last;
  }
}

Adding the above gets me no further than a 404 error page when I try and visit http://www.domain.co.uk/de/my_page.

So, I figured maybe this was something to do with the fcgi_param SCRIPT FILENAME so I changed that to: (added de to end of path)

fastcgi_param SCRIPT_FILENAME /var/www/vhosts/spectrumhealthcare.co.uk/http/de$script;

Doing this now gives me a No input file specified error when I visit http://www.domain.co.uk/de/my_page.

I'm kind of at a brick wall now so really helping the SO community can help me. You haven't let me down yet :).

A: 

I can answer my own question. Looks like I had language rewrite rule slightly wrong. Is should look like this:

location /de {
  if (!-e $request_filename) {
    rewrite ^/de/(.*)$ /de/index.php/$1 last;
  }
}
aaronrussell