Need Help Converting .htaccess to Nginx Configuration File

Edho P Arief edhoprima at gmail.com
Tue Jan 5 09:11:34 MSK 2010


On Tue, Jan 5, 2010 at 12:31 PM, Kevin Yusharyahya <lists at ruby-forum.com> wrote:
> Hi all,
> I just moved my site from an Apache-based webserver into a Nginx-based
> webserver. As a result, all of my site's permalinks are broken. Can
> anyone help me convert my .htaccess into Nginx configuration files?
> Here's my .htaccess - for your information, I'm just running a simple
> WordPress site. The .htaccess is on /, not on some /dir/.
>
> <IfModule mod_rewrite.c>
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule . /index.php [L]
> </IfModule>
>
> I read some articles in the web and after trying to convert it myself
> here's what I get.
>
> if (!-f $request_filename){
>  set $rule_0 1$rule_0;
> }
> if (!-d $request_filename){
>  set $rule_0 2$rule_0;
> }
> if ($rule_0 = "21"){
>  rewrite /. /index.php last;
> }
>
> Is that right? Where should I put that? In
> /usr/local/nginx/conf/nginx.conf? I have three sites running in three
> domains in the server and I just want this to run at one domain.
> --

ver. 1:

server {
  listen <port>;
  server_name <something>;

  ...(root, etc)...

  location / {
    try_files $uri $uri/ /index.php;
  }

  location ~ \.php$ {
    ...(something)...
  }
}

ver. 2:

server {
  listen <port>;
  server_name <something>;

  ...(root, php, etc)...

  location / {
    try_files $uri $uri/ @fallback;
  }

  location @fallback {
    fastcgi_param SCRIPT_FILENAME /path/to/index.php;
    ...(something)...
  }
}

-- 
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the nginx mailing list