2016-04-25 62 views
0

目前,當我訪問我的網站時,我得到了與users.cgi一起呈現,這工作正常。.htaccess - 如果文件不存在,重定向到新文件夾

但是我希望做的是檢查文件是否在我的根目錄存在,如果它存在,則向用戶發送到新的/ index.php的

文件我期待對於是done.txt

如果存在的話再進行正常的,如果沒有得到新的/ index.php文件

這是我目前的.htaccess

AuthType Basic 
AuthName "LogIn Name" 
AuthUserFile /user/local/idlist 
Require valid-user 
DirectoryIndex users.cgi 
Options +ExecCGI 

可以這樣做嗎?

感謝

回答

0

您可以使用以下規則:

RewriteEngine on 

#if file exists then carry on as normal 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 
#otherwise rewrite to /new/index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule^/new/index.php [L] 
+0

感謝。該文件實際上並未被網絡服務器使用,但會位於同一個文件夾中。用戶將永遠不會嘗試訪問該頁面。我只想檢查它是否存在,如果不存在則重定向。謝謝 – Tom