【问题标题】:Friendly URLS with nginx使用 nginx 的友好 URL
【发布时间】:2014-07-26 22:33:33
【问题描述】:

好的,我现在在 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//about-me"

我应该怎么做才能像在 apache 中那样重定向 url?

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

【问题讨论】:

    标签: .htaccess url nginx


    【解决方案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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 2017-03-21
      • 2021-07-23
      相关资源
      最近更新 更多