2017-05-24 65 views
0

如何允許使用.htaccess查看(/../)subfolder中的文件?如何允許使用.htaccess在(/../)subfolder中查看文件?

文件夾結構:

root/ 
root/.htaccess 
root/public 
root/public/.htaccess 
root/public/index.php 
root/public/css 
root/public/js 

根/ htaccess的

RewriteEngine On 
RewriteBase/
Options -MultiViews 
<FilesMatch ".*"> 
    Deny from all 
</FilesMatch> 

#i tried to add here, public directory permission, but it does not work 
#with DirectoryMatch i am getting the error The server encountered an internal error or misconfiguration and was unable to complete your request. 
#without DirectoryMatch i am getting the error You don't have permission to access /type705b/public/index.php on this server. 
<DirectoryMatch "/public.*"> 
Allow from All 
</DirectoryMatch> 

根/公共/ htaccess的

RewriteEngine On 
RewriteBase /public/ 
Options -MultiViews 
#wrong according comments <FilesMatch "public.*" > 
    Allow from all 
#</FilesMatch> 
#the rest of htaccess below 

如果我嘗試查看根/公共/ index.php的,我得到的錯誤:Forbidden You don't have permission to access /root/public/index.php on this server.

更正後,我得到The server encountered an internal error or misconfiguration and was unable to complete your request. 的錯誤日誌,上面的代碼表示xxx/htdocs/root/.htaccess: <DirectoryMatch not allowed here

+0

[.htaccess可能的重複。拒絕根目錄,允許特定的子文件夾。可能?](https://stackoverflow.com/questions/7649794/htaccess-deny-root-allow-specific-subfolder-possible) – matiaslauriti

回答

1

如果我沒看錯,你有<Files ~ "^public.*" >,這是錯誤的。

正確的應該是<Files ~ ".*" >,因爲你已經擁有了RewriteBase /public/


<Files ~ "^public.*" >將只允許符合public.*但作爲文件名,而不是一個路徑,也沒有目錄的文件。

+0

謝謝你,它仍然無法正常工作,現在我收到錯誤'遇到服務器內部錯誤或配置錯誤,無法完成您的請求。' –

+0

看看您的錯誤日誌'/ var/log/apache2/error.log' – matiaslauriti

+0

[Wed May 24 17:51:19.948912 2017] [core:警報] [pid 4892:tid 1232] [client :: 1:53133] xxx/root/.htaccess:

2

因爲你沒有在任何public/.htaccess重寫規則,你真的不需要任何東西比public/.htaccess此行其他:

Allow from all 

而且Files指令用於匹配文件名,只有這樣它可以從不匹配包含目錄的文件路徑。

+0

同樣,你可以在你的網站根目錄下有'Deny from all'.htaccess – anubhava

+0

謝謝,但它不起作用。添加允許公開,給出'服務器遇到內部錯誤或配置錯誤,無法完成您的請求。' –

+0

爲什麼要添加'allow fall'?我寫了'允許所有' – anubhava

0

工作組合,以允許查看在一個文件中(/../)subfolder使用。htaccess:

文件夾結構:

root/ 
root/.htaccess 
root/public 
root/public/.htaccess 
root/public/index.php 
root/public/css 
root/public/js 

根/ htaccess的

RewriteEngine On 
RewriteBase/
Options -MultiViews 
Deny from all 

root/public/.htaccess

RewriteEngine On 
RewriteBase /public/ 

Options -MultiViews 
Allow from all 
#the rest of code 

使用<File > <FileMatch > <Directory > <DirectoryMatch >給出錯誤。

+0

這正是我在答案中寫的。你甚至不需要在兩個.htaccess中都有'RewriteEngine'和'RewriteBase'這兩行 – anubhava

相關問題