.htaccess 如何将htaccess转换为nginx

7qhs6swi  于 2023-01-17  发布在  Nginx
关注(0)|答案(2)|浏览(183)

我在将htaccess文件转换为nginx时遇到了问题。也许有人可以帮助我。
我需要转换以下代码:

Options +FollowSymLinks -MultiViews
RewriteEngine On 
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index\.php/$1 [L,QSA]

我试过这个,但根本不起作用:

location / {
    try_files $uri $uri/ /index.php?$args;
}
aurhwmvo

aurhwmvo1#

一个一个
(我假设您的.htaccess文件位于文档根目录中。)
Apache RewriteRule指令将URL路径作为路径信息传递给index.php脚本,因此Nginx指令应该如下所示:

location / {
    try_files $uri $uri/ /index.php$uri$is_args$args;
}

$uri已经包含了斜杠前缀,Apache默认也会传递查询字符串,但是在Nginx中需要附加$is_args$args(当$args(查询字符串)非空时,$is_args只包含?)。

j2cgzkjk

j2cgzkjk2#

我发现这很管用:

if (!-e $request_filename) {
    rewrite ^/(.*)$ /index.php?$1;
}

但它安全吗?

相关问题