2014-03-18 107 views
4

我需要從apache更改爲Nginx,但.htaccess不適用於Nginx服務器。apache .htaccess到nginx重寫規則

我得到了以下在我的Apache .htaccess

RewriteEngine On 

# always run through the indexfile 
RewriteRule .$ index.php 

# don't let people peek into directories without an index file 
Options -Indexes 

當我把一個.htaccess Nginx的服務器上,該文件被由服務器中刪除。 在什麼樣的文件我必須把.htaccess數據(名稱和後綴),以及如何重寫Nginx和我把文件放在哪裏?

我希望所有子目錄中的文件都要經過我的index.php文件,這樣我可以從我index.php文件中包含特定的文件...

我已經試過類似:

# nginx configuration 

autoindex off; 

location/{ 
    rewrite .$ /index.php; 
} 

,但它不工作。該目錄看起來是這樣的:

── root 
    ├── folder1 
    │   └── folder2 
    │    └── file.php 
    └── index.php 

,所以如果我問root/folder1/folder2/file.php我希望服務器加載root/index.php,因爲我仍然有服務器的URL請求, 我可以從我index.php

包括root/folder1/folder2/file.php它所有的工作都在我的apache安裝上,但不在Nginx服務器上。 請幫幫我。

編輯: 原來,nginx.conf文件必須是根文件夾上方,如果你有機會到根文件夾上面的文件夾才能訪問。像服務器管理員訪問是必要的。

+0

您是否發現** http://www.anilcetin.com/**或** http://winginx.com/en/ htaccess的**? – MonkeyZeus

+0

是的和許多其他網站。我試圖把我的代碼放在nginx.conf和nginx.conf.txt文件夾中,但不起作用。 nginx服務器會自動刪除htaccess文件。代碼是否在htaccess文件中? – Medda86

回答

3

Nginx不會做htaccess文件。代碼需要進入nginx配置文件。此外,請嘗試將「最後一個」標記添加到重寫中:

# nginx configuration 

autoindex off; 

location/{ 
    rewrite .* /index.php last; 
} 
+0

是文件將被稱爲nginx.conf並由index.php在根文件夾中? – Medda86

+1

@ user3434534否。[請參見初學者指南中的第三段,它告訴你它在哪裏](http://nginx.org/en/docs/beginners_guide.html)。它在不同的系統上有所不同。 –

+0

如果我沒有權限訪問根目錄,是否可以使用放置在我正在使用的目錄中的自己的nginx.conf文件覆蓋它? – Medda86