php – CodeIgniter的Nginx重写规则

前端之家收集整理的这篇文章主要介绍了php – CodeIgniter的Nginx重写规则前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是英文规则:

Any HTTP request other than those for index.PHP,assets folder,files folder and robots.txt is treated as a request for your index.PHP file.

我有一个.htaccess文件,可以在Apache服务器上正常工作:

@H_502_13@RewriteCond $1 !^(index\.PHP|assets|files|robots\.txt) RewriteRule ^(.*)$index.PHP/$1 [L]

此规则的一些正确结果:

example.com = example.com/index.PHP

example.com/index.PHP/welcome = example.com/welcome

example.com/assets/css/main.css!= example.com/index.PHP/assets/css/main.css

我尝试了一些工具从htaccess规则转换为Nginx规则,但都是不正确的.

通过http://winginx.com/htaccess(缺少资产文件夹的例外规则……):

@H_502_13@location / { rewrite ^(.*)$/index.PHP/$1 break; }

通过http://www.anilcetin.com/convert-apache-htaccess-to-nginx/($1值中的错误):

@H_502_13@if ($1 !~ "^(index.PHP|assets|files|robots.txt)"){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ rewrite ^/(.*)$/index.PHP/$1 last; }

我怎样才能解决这个问题?调试规则真的很难.

到目前为止,这是我的Nginx配置:

@H_502_13@server { listen 80; server_name www.example.com example.com; location / { try_files $uri $uri/ /index.PHP?/$request_uri; } location ~ \.PHP${ root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; include fastcgi_params; } location ~ /\.ht { deny all; } }
最佳答案
您可以将其添加到您的配置:

@H_502_13@location ~* ^/(assets|files|robots\.txt) { }

这将适用于您的位置/规则.

您的配置还需要添加根文档和默认索引文件.

@H_502_13@... root /ftp/wardrobe; index index.PHP index.html index.htm; location / { try_files $uri $uri/ /index.PHP?/$request_uri; } location ~* ^/(assets|files|robots\.txt) { } ...

猜你在找的Nginx相关文章