将 .htaccess 转换为 nginx

将 .htaccess 转换为 nginx

又是我 :( 我试图在我的网络服务器上安装 siwapp 但无法使其与 nginx 一起工作,这里是 .htaccess 文件内容:

RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule (.*)\.php$ index.php/$1


RewriteCond $1 !^(index\.php|nhototamsu|assets|cache|xd_receiver\.html|photo|ipanel|automap|xajax_js|files|robots\.txt|favicon\.ico|ione\.ico|(.*)\.xml|ror\.xml|tool|google6afb981101589049\.html|googlec0d38cf2adbc25bc\.html|widget|iradio_admin|services|wsdl)

RewriteRule ^(.*)$ index.php/$1 [QSA,L]

当我访问http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.htmlnginx 无法正确显示页面,提示:“404 Not Found”(新 URL:http://myurl.com/tin-tuc/tuyen-sinh/tu-van/2012/04/25757-phan-van-qua-giua-khoi-a1-va-khoi-a.html

答案1

对我来说这看起来像是一个非常标准的配置...

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    rewrite ^/(.*)$ /index.php/$1;
}
location ~ \.php$ {
    try_files $uri $uri/ /index.php?$args;
    include fastcgi_params;
    fastcgi_pass localhost:9000;
}

答案2

网站工具帮了我很多忙

请从 nginx wiki 中了解重写工作原理这里相信我,这总是一个好主意

答案3

我可以给你一个真实的例子。

Apache 的.htaccess

Rewriterule ^(articulos)/([0-9]+)/([a-zA-Z0-9_-]+)$ index.php?modules=full_post&id=$2 [NC,L,QSA]

Nginx 等效项:

location / {
    try_files $uri $uri/ @rewrite;
}
location @rewrite {
    # Dinamic Links
    rewrite ^/(articulos)/([0-9]+)/([a-zA-Z0-9_-]+)$ /index.php?modules=full_post&id=$2;
}

我希望这可以帮助你!

相关内容