将mod_rewrite Apache转换为Nginx?

时间:2012-07-20 03:49:22

标签: apache mod-rewrite nginx

我是互联网编程的新手。我想将Apache切换到Nginx Web服务器,但在Nginx模式重写时仍然存在问题。

/home/user/public_html/read/上的我的网站位置以及.htaccess上我之前的/home/user/public_html/read/.htaccess文件,如下所示:

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]

如何将此mod_rewrite转换为nginx? (我很神奇,因为我的英语拼写不完美)

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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ãoSoepurquê,mas,alterando de break para last funciona。