2017-04-01 83 views
0

我一直在努力將我過去的apache重寫規則轉換爲nginx(也不確定是否將它放在正確的位置,所以如果能告訴我在哪裏可以告訴我,放好它)。如何將此apache重寫規則轉換爲nginx

基本上這是WordPress的在我的.htaccess文件的Apache重寫規則:

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^/?hosts/(.*)$ /user/$1 [R,L] 
</IfModule> 

正如你所看到的,我使用的這個規則,以便從重定向到example.com/hosts/username例子。 com/user/username

我已經使用這個轉換工具https://labs.gidix.de/nginx/,它輸出這個轉換:rewrite ^/?hosts/(.*)$ /user/$1 last; - 但我試着把它放在Ajenti(控制面板)高級自定義配置中,但它不工作。

+0

嘗試這種::'位置/ { 重寫^ /主機/(.*)$ /用戶/ $ 1重定向; }' –

回答

0

您可能需要將其設爲外部重定向,這樣WordPress纔會注意到。最乾淨的解決辦法是將其放置到自己的位置:

location ^~ /hosts/ { 
    rewrite ^/hosts(.*)$ /user$1 permanent; 
} 

更多見this document。 ?

1

作爲一個選項

location ~ ^/hosts/(.*)$ { 
    return 301 $scheme://$host/user/$1; 
}