【问题标题】:Transform Apache Rules to Nginx将 Apache 规则转换为 Nginx
【发布时间】:2016-08-31 01:16:02
【问题描述】:

我想将 Apache Web 服务器移动到 ngnix 网络服务器,但是如何将这些 Apache 规则更改为 ngnix。 我的主站点中有一个 .htaccess 文件,在子目录中有一个 .htaccess 文件

主站点 .htacess 重写引擎开启

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  !^/index.php
RewriteRule ^(.*)$ zzz.php?hash=$1   [L]
</IfModule>

在子目录.htacess 规则中

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI}  !^/index.php
RewriteRule ^(.*)$ host.php?hash=$1 [L,QSA,NC]
</IfModule>

【问题讨论】:

标签: apache .htaccess nginx


【解决方案1】:

在 nginx 中不要为此使用重写规则,try_files 会快得多:

try_files $uri $uri/ /index.php$is_args$args;

您当然可以根据需要设置任意数量的项目并更新脚本名称,例如:

try_files $uri $uri/ /$uri.php$is_args$args; /index.php$is_args$args =404;

可以在 nginx 配置的 server 或 location 部分使用: http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

Nginx 没有类似 .htaccess 的东西

【讨论】:

    猜你喜欢
    • 2019-03-10
    • 1970-01-01
    • 2019-09-13
    • 2016-06-18
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多