Forum Moderators: phranque
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 ('.:')?
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.