【问题标题】:Apache Rewrite to nginx syntaxApache 重写为 nginx 语法
【发布时间】:2012-11-23 08:28:16
【问题描述】:

我在 .htaccess 文件中有这个 apache 重写规则,并希望将其转录到 nginx。

 Options +FollowSymlinks
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^([^/]+)/([^/]+)(.*)$ /$3?$1=$2 [N,QSA]

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: apache .htaccess nginx


    【解决方案1】:

    您可以尝试使用 Nginx 的新规则: http://wiki.nginx.org/NginxHttpRewriteModule

    【讨论】:

    • 我对 nginx 重写不熟悉。上面的 nginx 等效项是什么?
    【解决方案2】:

    一般来说,apacahe 节:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule <regeg> <target>
    

    应替换为 nginx 等效项:

    location ~* <regex> { try_files $uri $uri/ <target>; }
    

    所以在您的情况下,您需要将以下位置添加到您网站的 nginx server-block:

    location ~* ^([^/]+)/([^/]+)(.*)$ { try_files $uri $uri/ /$3?$1=$2; } 
    

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 2012-05-28
      • 2019-12-19
      • 2016-01-16
      • 2022-01-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多