简体   繁体   English

需要帮助将Apache2重写规则转换为Nginx

[英]Need help converting Apache2 Rewrite rules to nginx

I've managed to convert most of them, but I'm struggling a bit with these two - 我设法转换了其中的大多数,但是我在这两个方面有些挣扎-

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L]

RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php

Would appreciate a hand if anyone is a nginx rewrite ninja :) 如果有人是nginx重写忍者,将不胜感激:)

This: 这个:

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L]

will be converted to: 将转换为:

rewrite ^/(.+)/$ http://$http_host/$1 permanent;

and this: 和这个:

RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php

will be converted to: 将转换为:

rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php;

you can also use: 您还可以使用:

if ($rule_0 = ""){
    rewrite ^/(.+)/$ http://$http_host/$1 permanent;
}
if ($rule_0 = ""){
    rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php;
}

Documentation: http://wiki.nginx.org/HttpRewriteModule 文档: http : //wiki.nginx.org/HttpRewriteModule

From: http://www.anilcetin.com/convert-apache-htaccess-to-nginx/ 来自: http : //www.anilcetin.com/convert-apache-htaccess-to-nginx/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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