duanjiao5082 2008-09-30 12:29
浏览 162
已采纳

htaccess文件,php,包含目录,以及windows XAMPP配置的噩梦

XAMPP makes configuring a local LAMP stack for windows a breeze. So it's quite disappointing that enabling htaccess files is such a nightmare.

My problem:
I've got a PHP application that requires apache/php to search for an /includes/ directory contained within the application. To do this, htaccess files must be allowed in apache and the htaccess file must specify exactly where the includes directory is.

Problem is, I can't get my apache config to view these htaccess files. I had major hassles installing this app at uni and getting the admins there to help with the setup. This shouldn't be so hard but for some reason I just can't get apache to play nice.

This is my setup:

c:\xampp
c:\xampp\htdocs
c:\xampp\apache\conf\httpd.conf - where I've made the changes listed below
c:\xampp\apache\bin\php.ini - where changes to this file affect the php installation
It is interesting to note that c:\xampp\php\php.ini changes mean nothing - this is NOT the ini that affects the php installation.

The following lines are additions I've made to the httpd.conf file

#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>

The following is the entire htaccess file contained in: 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="  

The includes directory exists at the location specified.

When I try to access the application I receive the following error:

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

Fatal error: require() [function.require]: Failed opening required 'include.general.inc' (include_path='.;C:\xampp\php\pearandom') in C:\xampp\htdocs\application\menu\logon.php on line 21

The include path c..andom\ is specified in the php.ini file listed above. The xampp install fails to allow another include path as specified in the htaccess.txt file.

Please help! I'm guessing there's probably an error with the httpd.conf OR the htaccess.txt file.. but it doesn't seem to be reading the htaccess file. I've tried to be as thorough as possible so forgive the verbosity of the post.

Now I know a workaround could be to simply add the include_path to the php file, but I'm not going to have access to the php.ini file on the location I plan to deploy my app. I will, however, be able to request the server admin allows htaccess files.

Update: renamed htacces.txt to .htaccess and ammended the appropriate directives in the httpd.conf file and all seems to work. The application suggested the naming of htaccess.txt and the ammended directives in the httpd. These are obviously wrong (at least for a xampp stack). Thanks for the help.

By the way, using ini_set() is a much friendlier way if the app needs to be deployed to multiple locations so thanks especially for that pointer.

  • 写回答

6条回答 默认 最新

  • donglisi8644 2008-09-30 12:39
    关注
    1. Why do you need to rename .htaccess to htaccess.txt
    2. Try setting the include_path using set_include_path() and see if that helps (as an intermediate fix)
    3. Verify which php.ini to use through a phpinfo()
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)