【问题标题】:Nginx Rewrite Multiple RuleNginx 重写多个规则
【发布时间】:2020-03-07 19:35:43
【问题描述】:

我正在尝试将我的服务器移至 Nginx 以进行试用。但是,当我将 htaccess 代码传输到 conf 文件时,出现 404 错误。如何让 Nginx 下面的代码重写兼容?

RewriteEngine on

RewriteRule ^firmaekle\.html$ /firmaekle.php [L,QSA,R=301]
RewriteRule ^/d/([^/]*).([^/]*)\.html$ /index.php?site=$1&site2=$2 [L,QSA,R=301]
RewriteRule ^u/([^/]*)([^/]*)\.html$ /uzgun.php?site=$1&site2=$2 [L,QSA,R=301]
RewriteRule ^y/([^/]*)([^/]*)\.html$ /yonlendir.php?firma=$1&uzanti=$2 [L,QSA,R=301]
RewriteRule ^ye/([^/]*)([^/]*)\.html$ /yonlendir2.php?firma=$1&uzanti=$2 [L,QSA,R=301]

【问题讨论】:

标签: apache .htaccess nginx


【解决方案1】:

你可以这样做

server {
    server_name example.com;

    rewrite ^/firmaekle\.html$ /firmaekle.php permanent;

    rewrite ^//d/([^/]*).([^/]*)\.html$ /index.php?site=$1&site2=$2 permanent;

    rewrite ^/u/([^/]*)([^/]*)\.html$ /uzgun.php?site=$1&site2=$2 permanent;

    rewrite ^/y/([^/]*)([^/]*)\.html$ /yonlendir.php?firma=$1&uzanti=$2 permanent;

    rewrite ^/ye/([^/]*)([^/]*)\.html$ /yonlendir2.php?firma=$1&uzanti=$2 permanent;
}

【讨论】:

  • 我将代码添加到conf文件并重新启动Nginx。但是,我仍然收到 404 not found 错误。会议代码:gist.github.com/EmreKara5aya/ca67b906d623d5b10c97745a620aabce
  • 将它们从location 中添加到此处gist.github.com/EmreKara5aya/…
  • 我在你说的地方添加了代码,但我仍然收到 404 错误。
  • 这条命令curl http://127.0.0.1/firmaekle.html -v的输出是什么(替换它在另一台主机上的ip)
  • 你确定firmaekle.php存在于根文件夹/home/nginx/domains/domkap.com/public
猜你喜欢
  • 2016-02-29
  • 2010-11-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-04
  • 2013-08-05
  • 2013-10-12
相关资源
最近更新 更多