.htaccess 配置問題

.htaccess 配置問題

我在一個網域上使用兩個網站,例如:www.example.com 和 www.example.com/site2。我想知道在我的site2 上,在我的site2 中,它們是2 個資料夾,名稱為folder1和folder2,我的index.php位於folder2中,但是folder2中定義的方法的定義我透過.htaccess包含文件,但我無法取得這些文件資料夾 1 中的文件並在瀏覽器上收到錯誤 500 和 400,我正在使用以下行,但它們在 .htaccess 檔案中不起作用

下面的行工作正常

RedirectMatch ^/$ http://www.example.com.pk/site2/views/

AllowOverride All
php_value include_path ".:/home/example/public_html/site2/system"

答案1

您是否試圖包含您的方法和類別以供 PHP 使用?如果是這樣,您很可能會想使用include() 或 require() 函數在您的 PHP 程式碼中,而不是透過 Apache 進行。

我無法從你的問題中確切地看出你想要實現什麼目標。如果您確實需要使用 Apache 來包含,請擴展您的問題以提供更多詳細資訊。

答案2

另外,您目前的 .htaccess 檔案不包含文件,它僅設定 php 使用的包含路徑。所以,想像一下這個文件樹:

root
| - a
|   |- myphp.php
| - b
|   |- myinclude.extension

當您包含在 php 檔案 myphp.php 中時,通常您會這樣做:

<?php include('../b/myinclude.extension'); ?>

但設定後

AllowOverride All php_value include_path "root/b/"

你只需要輸入

<?php include('myinclude.extension'); ?>

但這確實沒有什麼大的差別不是嗎?請仔細閱讀 php.net 頁面中有關 include、require 和 include_once、require_once 的內容。

相關內容