English 中文(简体)
Converting an ExpressionEngine rewrite rule for and NginX server
原标题:

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 :).

最佳回答

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;
  }
}
问题回答

Should be straight forward, in nginx site config file for default language you do something like below:

location / {
  try_files $uri $uri/ /index.php?q=$uri&$args;
}

For other language support (say de/da/fr/ etc):

location /de {
  try_files $uri $uri/ /de/index.php?q=$uri&$args;
}




相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签