Url rewriting 在Nginx中重写URI
我正在尝试为我的框架设置URI路由,我目前正在使用nginx作为服务器,但问题是,当我尝试访问以下链接时,总是出现500个错误Url rewriting 在Nginx中重写URI,url-rewriting,nginx,Url Rewriting,Nginx,我正在尝试为我的框架设置URI路由,我目前正在使用nginx作为服务器,但问题是,当我尝试访问以下链接时,总是出现500个错误 http://localhost.framework/ http://localhost.framework/index.php/ 如果我使用以下链接访问该网站,它将正常工作: http://localhost.framework/index.php http://localhost.framework/index.php?/ 我的域配置如下: server {
http://localhost.framework/
http://localhost.framework/index.php/
http://localhost.framework/index.php
http://localhost.framework/index.php?/
server {
listen 80;
server_name localhost.framework;
root /var/www/ASFramework;
access_log /var/log/nginx/framework.access.log;
error_log /var/log/nginx/framework.error.log;
location / {
rewrite ^/(.*)$ /index.php/$1 last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/ASFramework$fastcgi_script_name;
}
}
基本上我要做的就是获取以下url
http://localhost.framework/controller/method/../
http://localhost.framework/index.php/controller/method/../
(error.log)
是:
2011/07/03 22:57:22 [error] 19837#0: *6 rewrite or internal redirection cycle while processing "/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/", client: 127.0.0.1, server: localhost.framework, request: "GET / HTTP/1.1", host: "localhost.framework"
有人能告诉我发生了什么,我如何修复它吗?您的重写规则会导致重定向周期。nginx递归地用
index.php/index.php
替换index.php/index.php
。因此,在第二次替换之后,您的新URL将是index.php/index.php/index.php
等等
你可能想要这样的东西:
location / {
rewrite ^/index.php\?action=(.*)$ /$1 last;
}
它将
index.php?action=someaction
重写为/someaction
您的重写规则会导致重定向循环。nginx递归地用index.php/index.php
替换index.php/index.php
。因此,在第二次替换之后,您的新URL将是index.php/index.php/index.php
等等
你可能想要这样的东西:
location / {
rewrite ^/index.php\?action=(.*)$ /$1 last;
}
它将index.php?action=someaction
重写为/someaction
试试这个:
location / {
if ($request_uri !~ "/(index\.php)") {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
试试这个:
location / {
if ($request_uri !~ "/(index\.php)") {
rewrite ^/(.*)$ /index.php/$1 last;
}
}
更改此行:
location ~ \.php$ {
为此:
location ~ \.php.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/ASFramework$fastcgi_script_name;
}
更改此行:
location ~ \.php$ {
为此:
location ~ \.php.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /var/www/ASFramework$fastcgi_script_name;
}
这不是框架的工作方式,框架将采用整个URI,即
index.php/controller/method/param
=>/controller.method/param
,然后使用它作为路由,这在Apache和Lighttpb中是完全可能的,我需要取http://host/controller/method/param
并在第一个/
之后对所有内容进行cat,并将其传递给index.php/$1
是的,我不久前进行了更新,感谢您的努力,尽管框架不是这样工作的,框架将采用整个URI,即index.php/controller/method/param
=>/controller.method/param
,然后将其用作路由,这在Apache和Lighttpb中是完全可能的,我需要取http://host/controller/method/param
并在第一个/
之后对所有内容进行cat,然后将其传递到index.php/$1
是的,我不久前更新了,不过还是要感谢您的努力