簡體   English   中英

htaccess-使公共目錄可訪問

[英]htaccess - make public directory accessible

是的,這個問題在這里被問了很多,沒有提供的解決方案對我有用。

文件夾結構

/
+-- _projects
|   +-- includes
|   |   |-- main.class.php
|   +-- scripts
|   |   |-- saveitems.php
|   +-- view
|   |   |-- layout.php
|   |-- index.php
|   |-- .htaccess
|     
+-- _pub
|   +-- img
|   |   |-- webicon_facebook.png
|   |   |-- webicon_twitter.png
|
+-- view
+-- includes
|-- index.php
|-- .htaccess

根目錄中的.htaccess文件:

Options -Indexes +FollowSymlinks
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]+)\/(.+)$ index.php?page=$1&item=$2 [L,QSA]
RewriteRule ^([a-z]+)$ index.php?page=$1 [L,QSA]

任務:使瀏覽器能夠訪問_pub中的任何文件夾或文件

我嘗試過的

  • 與使用.htaccess文件Satisfy Any Allow from all_pub
  • 禁用_pub文件夾中的RewriteEngine
  • 更改根htaccess文件,在RewriteBase \\正下方包含類似RewriteRule ^_pub/$ _pub/ [L] RewriteBase \\

奇怪的是,當瀏覽到_projects時,將訪問該文件夾中的索引文件,並且該文件夾中的網站會完美加載。 但是,當訪問_pub (沒有索引文件)時,我從主機收到403錯誤。

我很確定我在htaccess根文件中丟失了某些內容,這些內容將允許直接訪問_pub中的文件夾和文件,但我不知道是什么。

如果目錄索引是您的意圖,則不應使用Options -Indexes禁用目錄索引,而應使用Options +Indexes

聽起來您想將_pub視為例外:您不希望應用正常規則,並且希望直接訪問_pub所有文件而無需重寫。 有幾種方法可以在_pub創建更多.htaccess規則。

一種方法是通過添加負前瞻來更改DOCUMENT_ROOT已經存在的規則:

RewriteRule ^(?!_pub)([a-z]+)\/(.+)$ index.php?page=$1&item=$2 [L,QSA]
RewriteRule ^(?!_pub)([a-z]+)$ index.php?page=$1 [L,QSA]

嘗試該操作,而不更改您在問題中顯示的RewriteConds。

保持您的根.htaccess像這樣:

Options +Indexes +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} ^/_pub/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^([a-z]+)/(.+)$ index.php?page=$1&item=$2 [L,QSA]

RewriteRule ^([a-z]+)/?$ index.php?page=$1 [L,QSA]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM