Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当您使用try_文件时,如何将apacheqsa标志与nginx结合使用?_Apache_.htaccess_Mod Rewrite_Nginx_Rewrite - Fatal编程技术网

当您使用try_文件时,如何将apacheqsa标志与nginx结合使用?

当您使用try_文件时,如何将apacheqsa标志与nginx结合使用?,apache,.htaccess,mod-rewrite,nginx,rewrite,Apache,.htaccess,Mod Rewrite,Nginx,Rewrite,我想把一些apache规则转换成nginx规则,我是nginx新手 所以我搜索了又搜索;但是没有找到我想要做的。以下是我想在Nginx中转换的行: RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [N

我想把一些apache规则转换成nginx规则,我是nginx新手

所以我搜索了又搜索;但是没有找到我想要做的。以下是我想在Nginx中转换的行:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule (.*) index.php?page=$1 [NC,L,QSA]
以下是我尝试过的:

location ~ ^/(?<page>[^\/]+)$ {
   try_files $uri /index.php?page=$page;
}
location ~ ^/(?<page>[^\/]+)?(?<qsa>[.*]+)$ {
   try_files $uri /index.php?page=$page&$qsa;
}
location~^/(?[^\/]+)${
试一试文件$uri/index.php?page=$page;
}
位置~^/(?[^\/]+)(?[.]+)${
try_files$uri/index.php?page=$page&$qsa;
}
这不管用。我做错了什么

编辑
它太长了,所以我用PHP处理了它,但我仍然希望得到答案,我会慷慨地对待任何人,他们会很好地回答这个问题

ApacheQSA标志是查询字符串append,在Nginx世界中,查询字符串存储在
$args

因此,对于try_文件,类似的方法应该可以工作:

location ~ ^/(?<page>[^\/]+)$ {
   try_files $uri /index.php?page=$page&$args;
}
应该已经管理目录测试(目录访问的
$uri/
测试检查)、实际文件直接访问(
$uri
),然后以给定url作为页面参数回退到index.php

您当前的第一条apache规则是:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
它检查直接目录访问(
-d
)、直接文件访问(
-f
)、符号链接(
-s
)或直接文件大小大于0的访问(
-s
),最后一个是
-f
的子集,所以我不确定您是否需要它

所以我们唯一需要处理的是符号链接直接访问。这由nginx中的配置选项管理

disable_symlinks off;

对于NC标记,不区分大小写的模式比较,类似
/*
,模式中没有字符应该没有问题。

?@Sumurai8我看到了,但我不介意如何使其与try_文件一起工作。很遗憾,我对nginx不太了解,而且没有真正的nginx服务器来测试:——|我希望你得到答案;——)我也希望如此,thx:)(如果你想开始使用nginx,你可以在ubuntu下进行双启动,并且
获得nginx
;))非常感谢!为了解释正则表达式mmhhh,我想说我正在将URI从
/
解析为
/
,因为我在PHP脚本中使用它:)刚刚编辑过它!这是一个很好的方法,但是您忘记了
&
$page
$args
之间添加了您对答案的修复,使用
&
更好,您是对的。
disable_symlinks off;