【问题标题】:Converting Apache RewriteRule to Nginx Rewrite将 Apache RewriteRule 转换为 Nginx 重写
【发布时间】:2018-04-11 03:10:38
【问题描述】:

我对 Nginx 完全陌生,我已经编写了这个 Apache 代码,我曾经将它放入一个 .htaccess 文件中,但我很难将它转换为 Nginx。我知道将其放入哪个.conf 文件,但不知道如何编写此语法。

请指教。

RewriteRule ^([a-zA-Z0-9]+)$ profile.php?profile_username=$1
RewriteRule ^([a-zA-Z0-9]+)/$ profile.php?profile_username=$1

【问题讨论】:

    标签: php apache .htaccess nginx


    【解决方案1】:

    在 nginx 上这是:

    # nginx configuration
    
    location / {
      rewrite ^/([a-zA-Z0-9 /-]+)$ profile.php?profile_username=$1;
      rewrite ^/([a-zA-Z0-9 /-]+)/$ profile.php?profile_username=$1;
    }
    

    【讨论】:

    • 如果您有另一个 htaccess 可以转换为 nginx,请访问此站点:winginx.com/en/htaccess
    • 好吧,我遇到了这个问题,我已经有一个默认位置文件,由于 EasyEngine 无法编辑。当我创建新文件时,Nginx 给我一个错误,指出“nginx:[emerg] 重复位置“/”在”。因此,从文档中可以看出将 ^~ 而不是 / 放在位置之后。这个对吗?我不相信这是因为我的网站没有重写。来自文档
    猜你喜欢
    • 1970-01-01
    • 2016-06-18
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-19
    • 2012-09-02
    相关资源
    最近更新 更多