带有nginx的友好URLS

时间:2014-06-05 19:23:50

标签: .htaccess url nginx

好的,我现在在apache中设置了

RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !favicon.ico$

RewriteRule .* index.php/$0 [PT]

我有像http://addr.tld/index.php/site这样的网址,它可以正常使用apache。

我试图在nginx中重现它

   root   /home/maciekmm/www;
   index  index.php;

   location / {
    if (!-e $request_filename){
    rewrite ^(.*)$ /index.php/$1;
    }
    try_files $uri $uri/ =404;
  }

   location ~ .php$ {
     try_files $uri =404;
     fastcgi_split_path_info ^(.+\.php)(/.+)$;
     fastcgi_pass unix:/var/run/php5-fpm.sock;
     fastcgi_index index.php;
     include fastcgi_params;
   }

但是我得到了

  

重写或内部重定向循环,同时处理" /index.php//index.php//index.php//index.php//index.php//index.php//index.php//的index.php // //的index.php的index.php // // index.php的大约-ME"

我该如何操作,以便重定向网址,就像它在apache中这样做?

我旁边有一个php路由器,但是为了测试我禁用重定向,所以它只是打印目标。

1 个答案:

答案 0 :(得分:1)

试试这个

root   /home/maciekmm/www;
index  index.php;

location / {     try_files $uri =404;

  try_files $uri $uri/ @php;
}

location @php {
  rewrite ^(.*)$ /index.php$1;
}

location ~ "\.php(/|$)" {
  fastcgi_split_path_info ^(.+\.php)(/.+)$;
  fastcgi_pass unix:/var/run/php5-fpm.sock;
  fastcgi_index index.php;
  include fastcgi_params;
}