簡體   English   中英

.htaccess 文件,PHP,包括目錄和 windows XAMPP 配置噩夢

[英].htaccess files, PHP, includes directories, and windows XAMPP configuration nightmare

XAMPP 使為 Windows 配置本地 LAMP 堆棧變得輕而易舉。 所以令人失望的是,啟用.htaccess文件是一場噩夢。

我的問題:我有一個 PHP 應用程序,它需要 apache/php 來搜索應用程序中包含的/includes/目錄。 為此,Apache 中必須允許.htaccess文件,並且.htaccess文件必須准確指定包含目錄的位置。

問題是,我無法讓我的 Apache 配置查看這些.htaccess文件。 我在 uni 安裝這個應用程序並讓管理員在那里幫助設置時遇到了很大的麻煩。 這不應該那么難,但由於某種原因,我無法讓 Apache 玩得很好。

這是我的設置:

c:\xampp c:\xampp\htdocs c:\xampp\apache\conf\httpd.conf - 我在其中進行了下面列出的更改c:\xampp\apache\bin\php.ini - 對此文件的更改影響 PHP 安裝 有趣的是, c:\xampp\php\php.ini更改沒有任何意義——這不是影響 PHP 安裝的 ini。

以下幾行是我在httpd.conf文件中添加的內容

#AccessFileName .htaccess
AccessFileName htaccess.txt
#
# The following lines prevent .htaccess and .htpasswd
# files from being viewed by Web clients.
#
#<Files ~ "^\.ht">
<Files ~ "^htaccess\.">
    Order allow,deny
    Deny from all
</Files>

<Directory "c:/xampp/htdocs">
#
# AllowOverride controls what directives may be placed in
# .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All
#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all
</Directory>

以下是整個.htaccess文件包含在: c:\xampp\htdocs\application\htaccess.txt

<Files ~ "\.inc$">
  Order deny,allow
  Deny from all
</Files>

php_value default_charset "UTF-8"
php_value include_path ".;c:\xampp\htdocs\application\includes"
php_value register_globals 0
php_value magic_quotes_gpc 0
php_value magic_quotes_runtime 0
php_value magic_quotes_sybase 0
php_value session.use_cookies 1
php_value session.use_only_cookies 0
php_value session.use_trans_sid 1
php_value session.gc_maxlifetime 3600
php_value arg_separator.output "&amp;"
php_value url_rewriter.tags "a=href,area=href,frame=src,input=src,fieldset="

包含目錄存在於指定的位置。

當我嘗試訪問應用程序時,我收到以下錯誤:

Warning: require(include.general.inc) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\application\menu\logon.php on line 21

致命錯誤:require() [function.require]:在C:\xampp\htdocs\application\menu\logon.php中打開所需的include.general.inc (include_path='.;C:\xampp\php\pear\random') 失敗第 21 行的C:\xampp\htdocs\application\menu\logon.php

包含路徑c..\random\在上面列出的php.ini文件中指定。 XAMPP 安裝無法允許在htaccess.txt文件中指定的另一個包含路徑。

我猜httpd.confhtaccess.txt文件可能有錯誤。但它似乎沒有讀取.htaccess文件。 我試圖盡可能徹底,所以請原諒這篇文章的冗長。

現在我知道一種解決方法可能是簡單地將 include_path 添加到 PHP 文件,但我將無法訪問我計划部署我的應用程序位置上的php.ini文件。 但是,我將能夠請求服務器管理員允許.htaccess文件。

htacces.txt重命名為.htaccess並修改了httpd.conf文件中的相應指令,一切似乎都有效。 該應用程序建議命名htaccess.txt和 httpd 中的修正指令。 這些顯然是錯誤的(至少對於 XAMPP 堆棧而言)。

順便說一句,如果需要將應用程序部署到多個位置,使用 ini_set() 是一種更友好的方式,因此特別感謝該指針。

  1. 為什么需要將 .htaccess 重命名為 htaccess.txt
  2. 嘗試使用set_include_path()設置 include_path 並查看是否有幫助(作為中間修復)
  3. 通過phpinfo()驗證要使用的 php.ini

您可以使用 ini_set() 更改每個請求的 include_path。 這將完全避免使用 htaccess。

我的 htaccess 在 XAMPP 下工作正常 - 盡管默認情況下禁用了某些模塊 - 你確定你想要的模塊已啟用嗎?

我認為您正在尋找的 searchprase 是:

允許覆蓋所有

我的猜測是,在 xampp 中,您需要在 httpd.conf 中啟用 AllowOverride(通過 .htaccess)。 這是一種簡單的安全措施,可以防止新手安裝可破解的平台:P

您需要在主 http.conf 文件中啟用 AllowOverride All。 查看 XAMPP_DIR/apache/conf/http.conf 內部)

只需這樣做:

open file ...\xampp\apache\conf\httpd.conf

find line "LoadModule rewrite_module modules/mod_rewrite.so"

if here is a # before this line remove it.(remove comment)

它的工作

暫無
暫無

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

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