简体   繁体   中英

Convert mod_rewrite Apache to Nginx?

I'm newbie on internet programming. I want to switch Apache to Nginx web server but still problem on Nginx mode rewrite.

My website location on /home/user/public_html/read/ and my previous .htaccess file on /home/user/public_html/read/.htaccess like this:

Options +FollowSymlinks

RewriteEngine on

RewriteRule ^mangas/([^/]+)/([^/]+)/$ - [F,L] 
RewriteRule ^mangas/([^/]+)/$ - [F,L] 
RewriteRule ^mangas(/?)$ - [F,L]

RewriteRule ^([^/.]+)/([^/.]+)/([0-9]+)(/?)$ index.php?manga=$1&chapter=$2&page=$3 [L] 
RewriteRule ^([^/.]+)/([^/.]+)(/?)$ index.php?manga=$1&chapter=$2 [L] 
RewriteRule ^([^/.]+)(/?)$ index.php?manga=$1 [L]

How can I convert this mod_rewrite to nginx? (I'm soory because my english spell is not perfect)

Try these in your server{} :

location ~ ^/mangas/([^/]+)/([^/]+)/$ {
   return 403; 
} 
location ~ ^/mangas/([^/]+)/$ { 
   return 403; 
} 
location ~ ^/mangas(/?)$ { 
   return 403; 
}

location / { 
   rewrite ^/([^/.]+)/([^/.]+)/([0-9]+)(/?)$ /index.php?manga=$1&chapter=$2&page=$3 break; 
   rewrite ^/([^/.]+)/([^/.]+)(/?)$ /index.php?manga=$1&chapter=$2 break; 
   rewrite ^/([^/.]+)(/?)$ /index.php?manga=$1 break; 
}

O certo seria:

location ~ ^/mangas/([^/]+)/([^/]+)/$ {
   return 403;
}

location ~ ^/mangas/([^/]+)/$ {
   return 403;
}
location ~ ^/mangas(/?)$ {
   return 403;
}
location / {
   rewrite ^/([^/.]+)/([^/.]+)/([0-9]+)(/?)$ /index.php?manga=$1&chapter=$2&page=$3 last;
   rewrite ^/([^/.]+)/([^/.]+)(/?)$ /index.php?manga=$1&chapter=$2 last;
   rewrite ^/([^/.]+)(/?)$ /index.php?manga=$1 last;
}

Não sei porquê, mas, alterando de break para last funciona.

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