重写从htaccess转换为Nginx

时间:2016-09-19 12:00:20

标签: .htaccess mod-rewrite nginx

我需要将这个Apache .htaccess转换为Nginx:

RewriteEngine On
RewriteBase /

RewriteRule ^index.html /index.php?act=main [QSA,L]

RewriteRule ^tickets/?$ /index.php?act=tickets [QSA,L]
RewriteRule ^tickets/index.html?$ /index.php?act=tickets [QSA,L]


RewriteRule ^ticket/?([0-9]+)?/?$ /index.php?act=ticket&id=$1 [QSA,L]
RewriteRule ^ticket/?([0-9]+)?/index.html?$ /index.php?act=ticket&id=$1 [QSA,L]

RewriteRule ^new/?$ /index.php?act=new [QSA,L]
RewriteRule ^new/index.html?$ /index.php?act=new [QSA,L]

RewriteRule ^opu/?$ /index.php?act=opu [QSA,L]
RewriteRule ^opu/index.html?$ /index.php?act=opu [QSA,L]

RewriteRule ^opu/?([0-9]+)?/?$ /index.php?act=opu&dep=$1 [QSA,L]
RewriteRule ^opu/?([0-9]+)?/index.html?$ /index.php?act=opu&dep=$1 [QSA,L]

RewriteRule ^opu/ticket/?([0-9]+)?/?$ /index.php?act=opu&module=ticket&id=$1 [QSA,L]
RewriteRule ^opu/ticket/?([0-9]+)?/index.html?$ /index.php?act=ticket&module=ticket&id=$1 [QSA,L]

RewriteRule ^error/?$ /index.php?act=error [QSA,L]
RewriteRule ^error/index.html?$ /index.php?act=error [QSA,L]

RewriteRule ^logout/?$ /index.php?act=logout [QSA,L]
RewriteRule ^logout/index.html?$ /index.php?act=logout [QSA,L]

所以在谷歌搜索后我想出了:

    location = /index.html {
    try_files $uri $uri/ /index.php?act=main$args;
}
    location = /tickets/?$ {
    try_files $uri $uri/ /index.php?act=tickets$args;
}
    location = /tickets/index.html?$ {
    try_files $uri $uri/ /index.php?act=tickets$args;
}
    location = /ticket/?([0-9]+)?/?$ {
    try_files $uri $uri/ /index.php?act=ticket&id=$1$args;
}
    location = /ticket/?([0-9]+)?/index.html?$ {
    try_files $uri $uri/ /index.php?act=ticket&id=$1$args;
}
    location = /new/?$ {
    try_files $uri $uri/ /index.php?act=new$args;
}
    location = /new/index.html?$ {
    try_files $uri $uri/ /index.php?act=new$args;
}
    location = /opu/?$ {
    try_files $uri $uri/ /index.php?act=opu$args;
}
    location = /opu/index.html?$ {
    try_files $uri $uri/ /index.php?act=opu$args;
}
    location = /opu/?([0-9]+)?/?$ {
    try_files $uri $uri/ /index.php?act=opu&dep=$1$args;
}
    location = /opu/?([0-9]+)?/index.html?$ {
    try_files $uri $uri/ /index.php?act=opu&dep=$1$args;
}
    location = /opu/ticket/?([0-9]+)?/?$ {
    try_files $uri $uri/ /index.php?act=opu&module=ticket&id=$1$args;
}
    location = /opu/ticket/?([0-9]+)?/index.html?$ {
    try_files $uri $uri/ /index.php?act=ticket&module=ticket&id=$1$args;
}
    location = /error/?$ {
    try_files $uri $uri/ /index.php?act=error$args;
}
    location = /error/index.html?$ {
    try_files $uri $uri/ /index.php?act=error$args;
}
    location = /logout/?$ {
    try_files $uri $uri/ /index.php?act=logout$args;
}
    location = /logout/index.html?$ {
    try_files $uri $uri/ /index.php?act=logout$args;
}

但是,该代码脚本会出现500错误,但它无法正常工作。唯一有效的是

    location = /index.html {
    try_files $uri $uri/ /index.php?act=main$args;
}

其他人没有。有人可以帮忙吗?

0 个答案:

没有答案