简体   繁体   English

配置Nginx将不存在的$ uri重定向为php文件作为GET参数

[英]Configure nginx to redirect non existing $uri to php file as a GET-parameter

I'm trying to redirect any url that doesn't point to a file/folder to a php file with the url as an argument to create an url shorter. 我正在尝试将没有指向文件/文件夹的任何URL重定向到以url作为参数的php文件,以创建更短的url。 This is my current code but the url doesn't seem to get passed to the php file: 这是我当前的代码,但是URL似乎没有传递到php文件:

location / {
    try_files $uri $uri/ /short/index.php?id=$uri;
}

Is this code correct and if so, why doesn't it work? 这段代码正确吗?如果正确,为什么不起作用?

Ok, so the problem was that $uri was including a leading / before the argument. 好的,所以问题在于$ uri在参数前包含了一个前导/。 So I just changed my php-script to remove the / and everything worked fine 所以我只是更改了我的php-script以删除/,一切正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM