我有各种各样的apache重写规则,我一直试图转换为nginx而没有太大的成功。我得到配置错误,或者没有正确重写。任何帮助将不胜感激。
RewriteEngine ON
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [L]
RewriteRule ^/([a-z]{2})/?$ /index.php?lang=$1 [QSA,L]
RewriteRule ^/([a-z]{2})/(.*) /$2?lang=$1 [QSA]
RewriteRule ^/categories/(.*) /index.php?cat=$1 [QSA]
RewriteRule ^/category-(.*) /index.php?cat=$1 [QSA,L]
RewriteRule ^/product-(.*) /product.php?id=$1 [QSA,L]
RewriteRule ^/auction-(.*) /auction.php?id=$1 [QSA,L]
RewriteRule ^/browse-(.*) /browse.php?id=$1 [QSA,L]
RewriteRule ^/browse /browse.php [QSA,L]
RewriteRule ^/item-(.*) /item.php?id=$1 [QSA,L]
RewriteRule ^/auctions/([0-9]+) /auction.php?id=$1 [QSA,L]
RewriteRule ^/help/faq/([0-9]+) /help/faq.php?cat=$1 [QSA,L]
RewriteRule ^/deal-([0-9]+) /deals/deal.php?id=$1 [QSA,L]
RewriteRule ^/gameplay/play-(.*) /gameplay/game_details.php?name=$1 [QSA,L]
RewriteRule ^/([^/]+)$ /$1/index.php [QSA,L]
答案 0 :(得分:0)
这是一个需要根据您的配置进行修改的最小配置块,您还需要在末尾添加php
捕获块
server {
listen 80;
server_name domain.com;
index index.php;
#rewrites start here
rewrite ^/([a-z]{2})/?$ /index.php?lang=$1&$query_string last;
rewrite ^/([a-z]{2})/(.*) /$2?lang=$1&$query_string last;
rewrite ^/categories/(.*) /index.php?cat=$1&$query_string last;
rewrite ^/category-(.*) /index.php?cat=$1&$query_string last;
rewrite ^/product-(.*) /product.php?id=$1&$query_string last;
rewrite ^/auction-(.*) /auction.php?id=$1&$query_string last;
rewrite ^/browse-(.*) /browse.php?id=$1&$query_string last;
rewrite ^/browse /browse.php$is_args$query_string last;
rewrite ^/item-(.*) /item.php?id=$1&$query_string last;
rewrite ^/auctions/([0-9]+) /auction.php?id=$1&$query_string last;
rewrite ^/help/faq/([0-9]+) /help/faq.php?cat=$1&$query_string last;
rewrite ^/deal-([0-9]+) /deals/deal.php?id=$1&$query_string last;
rewrite ^/gameplay/play-(.*) /gameplay/game_details.php?name=$1&$query_string last;
location / {
try_files $uri $uri/ /index.php$request_uri;
}
}