Switching to absolute paths broke site

This is the weirdest… I decided to switch all my links from relative to absolute. Because google says a site can be scraped easily if they’re relative. But now the includes don’t work!

It used to be that I had a blank root.php in my root folder. Then this at the top of every file which uses root to check which folder the file is in & then calls up the header:

<?php
     if (file_exists("./root.php")) {
     $rpath = ".";}
     else {
     $rpath = ".."; }
include("$rpath/1cde/header-test.php");
?>

and then I used relative links within the file like this:

<?php include("$rpath/1cde/head-test.php"); ?>

or:

<img src="<?php echo $rpath ?>/imgpg/logo410.gif" alt=

all I did was change the $rpath to absolute:

<?php include("http://greensmoothie.com/1cde/header-test.php"); ?>
<?php include("http://greensmoothie.com/1cde/head-test.php"); ?>

and everything vaporized…

Does anyone perhaps know why the includes stopped working just because I switched from relative to absolute?

thank you! - Val - http://greensmoothie.com/1cde/1mst-test.php

on localhost it displays like this:

I think you may have gotten confused.
What Google is talking about are HTTP links in HTML pages.
PHP uses file system paths that Google will not see.

I don’t know how much work you put into changing the paths in your PHP code, but I’m afraid the best I can suggest is to change them back to what you had that worked.

2 Likes

You’re doing all this using PHP. PHP is a server side language. What PHP does in the backend will not be visible in the front end unless of course you output something using something like echo.

Google will never know the path to your files. Google won’t even know that you used include().
You should be using relative links to images, that is generally good practice. From your link, I can see that images are working correctly for you.

So, revert to what you had working prior to this.
Let me also say that the error you’re seeing is cause by a setting in your php.ini file. See: allow_url_include()
You may need to turn that on in order to get rid of that error. However, even doing that will not solve your problem but I’m just pointing out the cause of the error.

Sites can be scraped very easily if they don’t have the URL include option turned off as then all the other site needs to do is to grab your includes and insert them into their page.

For security you should always restrict included to within your hosting account. For maximum security place the include files outside of the public_html where they can only be accessed via relative links from your hosting and where they don’t have an absolute address at all.

The only links Google sees are those between pages, not those within the PHP page source.

@Koobi

Let me also say that the error you’re seeing is cause by a setting in your php.ini file. See: allow_url_include()
You may need to turn that on in order to get rid of that error. However, even doing that will not solve your problem but I’m just pointing out the cause of the error.

Beware there are no errors, only warnings and for very good security reasons. This feature warns of any external .php files being called.

Edit:
The site breaks online because your security conscience host does not enable allow_url_include. Your online php error log file should have the notifications.

Hi - thank you for all the feedback. I know nothing about php. A very nice guy in this php forum years ago developed this root.php system for me.

What Google is talking about are HTTP links in HTML pages. PHP uses file system paths that Google will not see.

Google won’t even know that you used include(). You should be using relative links to images, that is generally good practice

your security conscience host does not enable allow_url_include.

I get it! So my includes should continue to go to $rpath. But the hrefs within that include can use absolute to make it tougher for scrapers. And my images should stay relative.

So for instance menu.php remains:

<?php include("$rpath/1cde/menu.php"); ?>

and any images inside menu.php remain relative like this:

<img src="<?php echo $rpath ?>/imgpg/buynow.gif"...

BUT hrefs inside menu.php can safely be absolute, like this:

<a href="http://greensmoothie.com/eat/rawfood.php">

whereas before that was:

<a href="<?php echo $rpath ?>/eat/rawfood.php">

For maximum security place the include files outside of the public_html where they can only be accessed via relative links from your hosting

Oh dear, that’s too complicated for me, because the file only knows which folder it’s in, in relation to root.php in root folder. If I start messing with that I’ll make a right mess-up since I don’t know what I’m doing anyway!!

thanks million for everyone’s help. It’s all working perfectly now.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.