1

我是互联网编程的新手。我想将 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?(我很抱歉,因为我的英语拼写不完美)

4

2 回答 2

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; 
}
于 2012-07-20T04:05:12.903 回答
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ão sei porquê, mas, alterando de break para last funciona。

于 2013-02-08T15:25:02.047 回答