2016-03-13 163 views
1

我有一個php文件的子文件夾。包含子文件夾.htaccess

像這樣:domain.com/subfolder/file.php

這將是調用PHP文件,就好像他們是在根文件夾中,而不會忽略現有的根文件非常有用的。

有沒有辦法通過.htaccess包含子文件夾及其所有內容?

回答

1

您可以使用以下規則根/的.htaccess:

RewriteEngine on 


#1--If the request is not for an existent root directory--# 
RewriteCond %{REQUEST_FILENAME} !-d 
#2--And the request is not for an existent root file--# 
RewriteCond %{REQUEST_FILENAME} !-d 
#3--Then, rewrite the request to "/subfolder"--# 
RewriteRule ^([^/]+)/?$ /subfolder/$1 [NC,L] 

上面的RewriteConditions對於避免重寫根文件夾和文件到/子文件夾很重要。

或者試試這個:

RewriteEngine on 
#--if /document_root/subfolder/foo is an existent dir--# 
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -d [OR] 
#--OR /document_root/subfolder/foo is an existent file--# 
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -f 
#--rewrite "/foo" to "/subfolder/foo--# 
RewriteRule ^(.+)$ /subfolder/$1 [NC,L] 
+0

第二個選項的作品!如何添加更多的文件夾?複製和粘貼相同的重寫會做或它可以瓶頸服務器? –

1

這樣的事情呢?

RewriteRule ^subfolder/(.*)$ $1 

應該幫我覺得

PS請確保阿帕奇重寫模塊啓用並在.htaccess文件打開的

相關問題