2017-06-30 75 views
0

我將我網站的所有內容(除主頁外)放入網站根目錄下的「內容」文件夾中。這是Apache 2.4.25。Alias將除主頁以外的所有內容匹配到「內容」文件夾

我想http://www.example.com服務於DirectoryIndex(即index.html)在C:/DocumentRoot/。以下工作正常。

<Directory "C:/DocumentRoot/website"> 
    Options None 
    AllowOverride None 
    Require all granted 
</Directory> 

然後我想有http://www.example.com/anything1/anything2服務DirectoryIndexC:/DocumentRoot/content/anything1/anything2。在添加以下內容之後,訪問http://www.example.com會出現Forbidden錯誤,但AliasMatch可以正常工作。

AliasMatch "^/(.+)$" "C:/DocumentRoot/website/content/$1" 
<Directory "C:/DocumentRoot/website/content/"> 
    Require all granted 
</Directory> 

任何想法發生了什麼或有更好的/工作的選擇?

回答

0

更改了AliasMatch所以它忽略了DirectoryIndexindex.html)使得它能夠達到預期效果。

AliasMatch "^/(?!index.html)(.+)$" "C:/DocumentRoot/website/content/$1" 

(?!index.html)確保隱index.html不匹配。 (.+)拿起任何東西,並將其從content文件夾中拉出。

0

在這種情況下,mod_rewrite稍微容易閱讀,然後在AliasMatch中稍後擴展否定斷言正則表達式。

RewriteEngine ON 
RewriteCond %{REQUEST_URI} !^/content 
RewriteRule ^/(.+) "C:/DocumentRoot/website/content/$1" 
+0

有了這個,不應該'http:// www.example.com/help'在'C:/ DocumentRoot/website/content/help'上拉上內容嗎?我在列出的「目錄」部分中的'Require all granted'後嘗試了您的答案(我先刪除了'AliasMatch')。 – user3071284

相關問題