2014-11-16 48 views
0

我是一個嘗試使用Nginx的Apache用戶,我真的無法理解如何轉換RedirectMatch 301。有人能更好地解釋它是如何工作的嗎?Nginx的RedirectMatch 301相當於

  • .htaccess版本:

RedirectMatch 301 /(tf2|cs|dota2|portal|hl|l4d|steam)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_/]+) /$1/$3

  • 我上/etc/nginx/sites-available/default文件的嘗試:

server { rewrite "^/(tf2|cs|dota2|portal|hl|l4d|steam)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_/]+)" /$1/$3 last; }

它打算redire ct例如。 mysite.com/tf2/this-will-be-removed/this-will-not/mysite.com/tf2/this-will-not/

謝謝!

回答

2

它應該是:

server { 

    server_name mysite.com; 

    location/{ 
     rewrite "^/(tf2|cs|dota2|portal|hl|l4d|steam)/([-\w]+)/([-\w/]+)$" /$1/$3 permanent; 
    } 

} 
+0

它的工作,非常感謝! –