【问题标题】:Apache to Nginx migration problemsApache 到 Nginx 的迁移问题
【发布时间】:2015-04-08 05:51:45
【问题描述】:

谁能告诉我如何将此规则从 apache 重写为 nginx?

我尝试了很多在线转换器,但都不起作用。

/hotel/.htaccess

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule    ^$    resources/    [L]
 RewriteRule    (.*) resources/$1    [L]
</IfModule>

/hotel/resources/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule ^(.*)$ index.php?url=$1 [PT,L,QSA]

</IfModule>

/hotel/resources/index.php

  if (!empty($_GET['url'])) {
    $GLOBALS['url'] = $_GET['url'];
   }
   require_once(PROJECT_ROOT . DS . 'config' . DS . 'config.inc.php');
   require_once(ROOT . DS . 'hvtengine' . DS . 'library' . DS . 'engine.inc.php');

我试过了:

location / {        
    rewrite ^/$ /resources/ last;
    rewrite /^(.*)$ /resources/$1 last;
    # try_files $uri $uri/ /index.php;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
}

location /resources/ {
    if (!-e $request_filename){
    rewrite ^(.*)$ index.php?url=$1 break;
    }
}

【问题讨论】:

  • 这应该接受哪些网址? /hotel 是 url 的一部分吗?

标签: php apache .htaccess mod-rewrite nginx


【解决方案1】:

由于所有请求都被重写为/resources/,我认为根本没有理由进行重写。就让它成为服务器的root

server {
    root /hotels/resources/;

    location / {
        try_files $uri /index.php?url=$uri;
    }

    location ~ \.php$ {
        # ... php stuff
    }
}

【讨论】:

  • 我已经改成接受$_GET,try_files $uri /index.php?url=$uri&$args;
猜你喜欢
  • 2016-05-03
  • 2014-05-28
  • 2014-06-04
  • 2011-06-03
  • 1970-01-01
  • 1970-01-01
  • 2016-12-26
  • 2019-05-11
  • 1970-01-01
相关资源
最近更新 更多