简体   繁体   中英

Apache to Nginx migration problems

can anyone tell me how to rewrite this rules from apache to nginx?

I have tried many online converters but doesn't work.

/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');

I have tried:

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;
    }
}

Since all requests are rewrited to /resources/ I see no reason to have that rewrite at all. Just let it be root of server.

server {
    root /hotels/resources/;

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM