繁体   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