【问题标题】:Convert HTACCESS mod_rewrite directives to nginx format?将 HTACCESS mod_rewrite 指令转换为 nginx 格式?
【发布时间】:2016-12-13 13:13:36
【问题描述】:

我是 nginx 的新手,我正在尝试转换我从 Apache 编写的应用程序,因为我需要能够同时为大量客户端提供服务,而无需大量开销!

我已经掌握了设置 nginx 和 FPM/FastCGI PHP 的窍门,但我还不能完全理解 nginx 的重写格式。我知道你必须在 nginx 配置中的 server {} 块中编写一些简单的脚本,但我还不熟悉语法。

任何对 Apache 和 nginx 都有经验的人可以帮我将其转换为 nginx 格式吗?提前致谢!

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^school\.dev$ [NC]
    RewriteRule ^(.*)$ http://www.school.dev/$1 [R=301,L]
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [NE,L]
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</IfModule>

【问题讨论】:

    标签: .htaccess nginx


    【解决方案1】:

    这是您的 htaccess 的 nginx 转换。

    # nginx configuration
    location / {
    if ($http_host ~* "^school\.dev$"){
    rewrite ^(.*)$ http://www.school.dev/$1 redirect;
    }
    if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?$query_string break;
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2021-01-01
      • 2013-02-02
      • 2021-11-26
      • 2020-12-23
      • 2012-07-19
      • 2018-07-10
      • 2017-08-02
      • 2011-05-07
      相关资源
      最近更新 更多