PDA

View Full Version : Trying to get files in subdirectories to pick up files in root using require() or inc



stalemath
11 Mar 2011, 12:00 AM
I'm just getting back into PHP after not having done any in years, and I can't figure this out. I am using require() on all my pages to get root/inc/head.php and root/inc/foot.php. I'm also using .htaccess which has the following:


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php


This way, I can hide the .php extensions.

Everything works fine on my pages that are stored in the root directory. My problem is this: My site includes a "services" section, and since this is split into several parts, I made a services directory in my root (public_html) directory. But I'm having trouble for them to pick up my required header and footer files from root/inc/. When I type things like
require ('/inc/head.php'); or
require ('../inc/head.php');, it gives me a PHP error saying it cannot be found. Do you think the .htaccess file has anything to do with it? What do you think my solution should be? Should I just put all the services pages in the root folder? That seems like it would be a simple solution but I'd really like to know a better way to do this.