Forum Moderators: phranque

Message Too Old, No Replies

Is .htaccess changing my php include path?

php, .htaccess, php_include path,

         

elbowlobstercowstand

4:26 am on Mar 20, 2008 (gmt 0)

10+ Year Member



Abstract

My beautiful .htaccess file is rendering the php include path changed AND additionally errors are NOT displayed on the page after .htaccess gets a hold of it. Not sure how this error is even possible! Enjoy my ginormous post.

First, here is what's setup on my server (garnered from phpinfo() function), and what works as expected:


displaly_errors = on
include_path= include_path='.:/var/www/vhosts/example.com'
open_basedir=/var/www/vhosts/example.com/httpdocs

And this is my .htaccess file:


#location of this file: /var/www/vhosts/example.com/httpdocs
RewriteEngine on
RewriteBase /
#
#REDIRECTS
#
# Externally redirect HTTP requests for "/secure" and "/owner" to HTTPS (SSL), except for css, jpg, jpeg, js, gif, and png files
RewriteCond %{REQUEST_URI} !\.(css¦jpeg¦js¦gif¦png)$ [NC]
RewriteCond %{REQUEST_URI} ^/folder/(secure¦owner)
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
#
# Externally redirect HTTPS requests for all except "/secure" and "/owner" to HTTP, except for css, jpg, jpeg, js, gif, and png files
RewriteCond %{REQUEST_URI} !\.(css¦jpeg¦js¦gif¦png)$ [NC]
RewriteCond %{REQUEST_URI} !^/folder/(secure¦owner)
RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
#
#INTERNAL REWRITES
#
# Simplerule: Internally rewrite all extensionless URLs to .php
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.php [L]

And this is my test file accessible via http://www.example.com/folder/test2:


<?php
#this function includes a file who simply echos some text
include('global-include/include.php');
include('global-include/does_not_exist.php');
?>

This is le output when you request the above page:


hello, the file got included
Warning: include(global-include/does_not_exist.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4
Warning: include(global-include/does_not_exist.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4
Warning: include() [function.include]: Failed opening 'global-include/does_not_exist.php' for inclusion (include_path='.:/var/www/vhosts/example.com') in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4

Enter the dragon, and the problem:

#everything stays the same, except .htaccess changes:


RewriteCond %{REQUEST_URI} ^/folder/(secure¦owner¦test2)
RewriteCond %{REQUEST_URI} !^/folder/(secure¦owner¦test2)

Now when you request the test2 page again, (http://www.example.com/folder/test2), it changes, as expected, to https, but the output is completely blank. A look in the error_log, however shows these errors:


[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include(global-include/include.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 3
[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include(global-include/include.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 3
[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'global-include/include.php' for inclusion (include_path='.:') in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 3
[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include(global-include/does_not_exist.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4
[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include(global-include/does_not_exist.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4
[Wed Mar 19 21:05:00 2008] [error] [client ip_address] PHP Warning: include() [<a href='function.include'>function.include</a>]: Failed opening 'global-include/does_not_exist.php' for inclusion (include_path='.:') in /var/www/vhosts/example.com/httpdocs/folder/test2.php on line 4

Any ideas how .htaccess could be moding my include path from what it was originally ('.:/var/www/vhosts/example.com') to the new value in the error logs ('.:')?

jdMorgan

4:59 am on Mar 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope this is not what's really in the file...

dis[b]plaly[/b]_errors = on

.htaccess has no effect on file includes, except in the directives at the top which are used to configure PHP.

Rewrites apply only to HTTP requests, and not to server-internal file includes.

Jim

elbowlobstercowstand

6:50 pm on Mar 21, 2008 (gmt 0)

10+ Year Member



Yikes... sorry about that typo! I actually have it right in my config file:

display_errors = on

Issue solved. Turns out the problem was that, when the redirect happens (from http to https) as expected, the server brings in a different config file.

http requests: vhosts.conf gets included in http.conf
https requests: vhosts_ssl.conf gets included in http.conf

Recall that in my original setup, I didn't even have a vhosts_ssl.conf file, but I did have a vhosts.conf which defined the include path (and things worked as expected on the http side).

To solve things, an admin simply duplicated my vhosts.conf file (which set the proper included path) and named it vhosts_ssl.conf, and now includes work as expected.

g1smd

9:06 pm on Mar 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can also set the PHP include value from within .htaccess itself:

php_value include_path /vhost/vhost4/e/x/a/example.com/www/includes