坚持将htacces转换为nginx规则

时间:2016-02-07 18:57:14

标签: apache .htaccess nginx server rules

为此尝试了一些在线转换器,但对我没什么用。

这是.htaccess代码 - 请帮助我让这个代码正常工作。

RewriteEngine On

RewriteRule ^(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ $1.php [QSA,L]

RewriteRule ^pages/([^\.]+)\.html$ page.php?prefix=$1 [QSA,L]

ErrorDocument 404 /error.php?code=404

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [S=5]
RewriteRule ^users/?((index)\.html)?$ users_list.php [QSA,L]
RewriteRule ^users/([0-9]+)/([^\.]+)\.html$ user_$2.php?id=$1 [QSA,L]
RewriteRule ^([^/\.]+)/?((index)\.html)?$ catgory.php?prefix=$1 [QSA,L]
RewriteRule ^([^\.]+)/([^\.]+)\.html view.php?cat=$1&id=$2 [L]

RewriteRule ^(sitemap|rss)\.xml $1.php [QSA,L]
RewriteRule ^sitemap_([0-9]+)\.xml sitemap.php?sitemap=$1 [QSA,L]

RewriteRule ^lang_pkgs\.js lang_pkgs.php [QSA,L]

AddType video/ogg .ogv
AddType video/mp4 .mp4
AddType video/webm .webm

修改:从2个不同的在线转换中添加了2个转换后的规则。我已经测试过,两者都没有用,给了我错误500.

rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php last;
    rewrite ^/pages/([^.]+).html$ /page.php?prefix=$1 last;
if (-f $request_filename){
    set $rule_2 1;
}
if (-d $request_filename){
    set $rule_2 1;
}
if ($rule_2 = "1"){
}
    rewrite ^/users/?((index).html)?$ /users_list.php last;
    rewrite ^/users/([0-9]+)/([^.]+).html$ /user_$2.php?id=$1 last;
    rewrite ^/([^/.]+)/?((index).html)?$ /catgory.php?prefix=$1 last;
    rewrite ^/([^.]+)/([^.]+).html /view.php?cat=$1&id=$2 last;
    rewrite ^/(sitemap|rss).xml /$1.php last;
    rewrite ^/sitemap_([0-9]+).xml /sitemap.php?sitemap=$1 last;
    rewrite ^/lang_pkgs.js /lang_pkgs.php last;

error_page 404 /error.php?code=404;
location /auth {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /my_posts {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /upcoming {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /contact {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /panel {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /login {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /account {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /register {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /recover {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /logout {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /search {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /random_post {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /index {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /ajax {
rewrite ^/(auth|my_posts|upcoming|contact|panel|login|account|register|recover|logout|search|random_post|index|ajax).html$ /$1.php break;
}
location /pages {
rewrite ^/pages/([^\.]+)\.html$ /page.php?prefix=$1 break;
}
location / {
if (-e $request_filename){
rewrite ^/users/?((index)\.html)?$ /users_list.php break;
}
rewrite ^/([^/\.]+)/?((index)\.html)?$ /catgory.php?prefix=$1 break;
rewrite ^/([^\.]+)/([^\.]+)\.html /view.php?cat=$1&id=$2 break;
}
location /users {
rewrite ^/users/([0-9]+)/([^\.]+)\.html$ /user_$2.php?id=$1 break;
}
location /sitemap {
rewrite ^/(sitemap|rss)\.xml /$1.php break;
}
location /rss {
rewrite ^/(sitemap|rss)\.xml /$1.php break;
}
location /sitemap_ {
rewrite ^/sitemap_([0-9]+)\.xml /sitemap.php?sitemap=$1 break;
}
location /lang_pkgs {
rewrite ^/lang_pkgs\.js /lang_pkgs.php break;
}

0 个答案:

没有答案