Need help with htaccess and php includes_path

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
I am trying to migrate a site over to a new webhost. It's mostly HTML/CSS, using PHP for includes. There is a default path to the includes directory. On the live servers, this was set up by a consultant (no longer available) using includes_path in php.ini, as well as some lines in my .htaccess file.

I have set up a test site on the new server, and have changed the includes path to the one on the new server (in htaccess and php.ini). But so far I can only get the includes to work on the Home page. Pages in subdirectories are blank where the includes should be, and the source code shows the includes are not being generated there. I have tried every combination of possibilities I can think of but can't get it to work on subdirectory files.

FYI: All of this is just the first step in eventually changing my http site to https, which has become necessary because some parts of the site are not working (data from an external site no longer showing on the live site, probably because they just updated to https). I figured as long as I'm doing all this, I might as well migrate to the new servers while I'm at it (which I've been meaning to do for some time). I'm using another domain I have to set up a test site before pointing the nameserver's over to the new server. Once I get it all working on the new server, I'll make the changes to https. Since my live site isn't working properly, I need to complete this initial step as soon as possible, so I can get the broken parts of my site working again under https.

HERE ARE SOME DETAILS:
What works on the Home page only is to put in php.ini the following line under Paths and Directories:
include_path = ".:/home/myusername/public_html/mydomain.com/includes"

The original site also has the following at the beginning of the htaccess file:
php_value include_path ".:/home/myusername/public_html/mydomain.com/includes"

The original site uses both the htaccess and php.ini lines, but when I use the php_value line in the htaccess of the test site, I get a 500 Internal Server Error. When I have only the include_path line in php.ini, it can find the includes only from the homepage but not on pages in subdirectories.

If you need to see the test site to help, please message me privately; I'd rather not put it in the forum.

I'm a bit desperate for help. I only have minimal knowledge about PHP and .htaccess, enough to know I need to go to other sites for code or help. I realize it's Friday night (this stuff only happens right before a weekend, right? lol) but I'm hoping someone might be around who could help me with this. I'm juggling this with other work this weekend, but I'll try to check in as often as I can.

I hope all this makes sense. Many, many thanks in advance.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,398
Check the include code for your subdirectory files, they should start with a ../ (one for every level down fr0m the include directory)
 

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
Hi JiminSA. Thanks for replying, and I understand what you're getting at. But actually, that isn't necessary for the includes, which was the whole point of doing the include_path -- so that the page file that's pulling in the include file can be in any directory at any level of the directory tree. The same include file (e.g. announcements, links to a specific section of the site, an ad, etc) will appear on many different pages, not all of which are on the same level relative to the root directory. By setting up the include_path that way, I only have to specify the name of the include file, for example:

<?php include('dailylinks.php'); ?>

...and it is automatically found in the includes directory. It works like a charm on the live site, but on the test site it can't seem to find the includes directory from anywhere south of the root directory.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,398
It works like a charm on the live site, but on the test site it can't seem to find the includes directory from anywhere south of the root directory.
Aha! By 'test site' do you mean on a local server (xaamp; wamp or whatever) or is it a test site on the internet?
If the former, then it's due to the differing Directory structures (e.g. localhost/mytestsite/includes as opposed to .:/home/myusername/public_html/mydomain.com/includes), if it's the latter then the same may apply, especially if the test site is resident in a sub-directory ...
 
Last edited:

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
No, the test site is installed on the webhost and the server where the live site will eventually be migrated to. I wanted to be sure I was testing it in the same environment as the migrated site will be.

By 'test site' I mean that I've uploaded a cloned version of the live site using an extra domain I have that I wasn't using. I've changed all references from the live domain name to the test domain name, so it shouldn't be about a conflict between the names -- otherwise I wouldn't be able to get the Home page includes to work.

Edited: both are Apache environments, as far as I know.
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,398
Ok so the root folder obviously has the same name (public_html, or whatever). but I would still double check that your structure is the same as your current live site - i.e. the exact path to your includes folder ...
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,398
otherwise I wouldn't be able to get the Home page includes to work.
Yes that's very true and by the way you say the includes path is resolved within the sub-directory pages, if it works for the index file, it should work for them.
Perplexing, but I am sure that it must be a difference in the structure below the root folder, that is causing the failure to pick up the includes folder:mad:
Shouldn't 'public_html' come after 'mydoman.com' ? - .:/home/myusername/public_html/mydomain.com/includes"
 

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
Yes that's very true and by the way you say the includes path is resolved within the sub-directory pages, if it works for the index file, it should work for them.
Perplexing, but I am sure that it must be a difference in the structure below the root folder, that is causing the failure to pick up the includes folder:mad:
Shouldn't 'public_html' come after 'mydoman.com' ? - .:/home/myusername/public_html/mydomain.com/includes"
Thanks very much for your continued help with this. In this case, the mydomain.com IS a subdirectory off of public_html, since it is an add-on domain (not my primary domain on that account). I wondered if the dot might be a problem and tried copying the includes files to another directory off public_html that didn't have a dot, but it didn't work either. Unless there's some weird thing that's not obvious, the path is accurate for the new server.

I've spoken extensively with the support people for that webhost (who are usually awesome) but because this is considered to get into the development area, this isn't really part of the support they offer. I may try again on Monday, when there might be more people around with expertise in the development side of things. If nothing else, they can hopefully at least confirm if the path is accurate.
 

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
I'm just now thinking of another possible factor in this. There were two things that were set up by the guy who did this years ago for the live site. One was to specify the default includes directory. The other was to set it up so that I could reach any file in any directory just by giving the path from the site's root directory.

So, for example, if I want to have an image in an include file that will be displayed on pages all over my site (on different directory levels), I only need to say src="/images/myimage.jpg" and it would be able to grab the image, no matter where it was relative to the page that was displaying it. I don't need to say src="../../images/myimage.jpg". Perhaps this feature is more what I need to focus on rather than the include_path?

The thing is, I'm not sure what is enabling the site to do this. There's a set of lines in htaccess that might be doing it (if not, I have no clue what they're doing), but if it's not them then I have no idea where or how that is set up. Is this something that might be done in php.ini as well? Or in htaccess? Or somewhere else? I'm just thinking maybe that is a separate thing that needs to be adjusted too, but I don't know where to look to do that.

Sorry if this seems fragmented. It's hard to know what you don't know. ;-)
 

JiminSA

Jim
Joined
Dec 15, 2011
Messages
3,398
Humour me, if you would ...
Drop the .htaccess and PHP.ini set up and simply change your includes on the pages to access the includes folder relatively:
PHP:
// In the index.php file:
    include "./includes/page1.php";
// In the downstream pages:
    include "../includes/page1.php";
I believe this to be simpler and more controllable;)
 

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
Yes, I was thinking that might be the most effective option at this point, until I can find the time to redo the site in something like Wordpress, but that is months away. Unfortunately, it's a big site and manually adding the relative path to every include will take a lot of time, which I was hoping to avoid since I don't really have the time for that right now either.

I did try to test just one of the includes on one of the pages, to see if it would find the file if I just put the path from the root directory (on the live site where it now, that's all I would need to do). But it didn't show unless I used a completely relative path (from page to file, not just from root to file). I didn't disable the php.ini or htaccess when I tested this.

So it seems there are two separate features happening on the original site -- the default directory for includes files, and the ability to simply give the path from the root (not the fully relative path).

The header on every page is an include file, and that doesn't show up on sub-pages unless I put in a fully relative path to that include file. BUT the links in that header file only give the path starting from the root directory. I *am* able to navigate from a page in one subdirectory (that I've forced to show the header) to a page in another subdirectory, using the header links without problems.

In other words, when I manually force the header include file to show (using a fully relative path) in a in subdirectory-A, I am able to navigate to a page in subdirectory-B by clicking on the header link to that page, even though the header link is only a root-to-page path. And on the sub-pages, where I have placed images using only a root-to-file path, the images seem to show up fine.

So the root-to-file path works in at least some cases; just not for includes.

So, I tried commenting out the include_path in php.ini, as well as in htaccess. Tried the root-to-file path for the heading on another subdirectory page, but it still doesn't show. Seems the only way I can get include files to show is by using a fully relative path.
 

ptwd

Thread Starter
Joined
Feb 16, 2017
Messages
11
No, please don't feel that way. At least you helped me explore the possible causes. I just wasn't sure if I was missing something. ---And I still might be, but at least we've checked off most of the options. I really appreciate your help. :) Enjoy the rest of your weekend.
 
Joined
Oct 30, 2017
Messages
1
Hey, Do you know about LongPathTool Software its can help you to fix your issues related file name too long, long file name delete.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top