【发布时间】:2014-08-24 17:02:27
【问题描述】:
我想将所有包含“xhr.php”的请求重写为/xhr.php,而不是原来的路径。
请求:
type: "POST",
url: "/system/classes/templates/address/xhr.getAddress.php",
data: vars,
dataType: "html"
应该以路径作为参数转到 /xhr.php。我试过这个:
rewrite ^/(.*)/xhr.(.*)\.php$ /xhr.php?parameter=$1¶meter2=$2 last;
但是它不起作用。有任何想法吗?我的配置如下所示:
location / {
root /var/www/http;
try_files $uri $uri/ index.php /index.php$is_args$args @rewrite;
}
location @rewrite {
rewrite ^/(.*)/xhr.(.*)\.php$ /xhr.php?parameter=$1¶meter2=$2 last;
}
这基本上可以用 nginx 实现吗?这里有什么问题? 谢谢:)
//编辑: 我解决了,但是看起来效率不高……
location / {
root /var/www/http;
try_files $uri $uri/ index.php /index.php$is_args$args;
}
if ($request_uri ~ .*/xhr.*) {
rewrite ^/(.*)/xhr.(.*)\.php$ /xhr.php?parameter=$1¶meter2=$2 break;
}
【问题讨论】: