how to deal with include_once php urls?

838 Views Asked by At

I'm building a static site and trying to get a bit modular on the code. Using include_once solves my problem, but the new created section.php file is seen as another URL on the server and IMHO creates a SEO problem - duplicate content. Thin theory, but still. Is there any solution to use include_once and mark those included files as non-existent for crawlers?

Just a code example, to better define what the problem is.

index.php looks like this:

<div id="wrapper">
    <?php include_once ('header.php'); ?>
    <div id="content">
        <h1>Title</h1>
        <p>Page content</p>
    </div>
</div>

header.php looks like this:

<div id="header">
    <ul class="menu">
        <li>
            <a href="/">Home</a>
        </li>
        <li>
            <a href="#">About</a>
        </li>
        <li>
            <a href="#">Contact</a>
        </li>
    </ul>
</div>

So generated code will render like this:

<div id="wrapper">
    <div id="header">
        <ul class="menu">
            <li>
                <a href="/">Home</a>
            </li>
            <li>
                <a href="#">About</a>
            </li>
            <li>
                <a href="#">Contact</a>
            </li>
        </ul>
    </div>
    <div id="content">
        <h1>Title</h1>
        <p>Page content</p>
    </div>
</div>

header.php is another file on the server and could be indexed by search engine, because it has its own URL. Question might be dumb and may have the simplest answer, I just don't know if I should use redirects or some other tweaks.

Thanks!

1

There are 1 best solutions below

1
On

You can do it by multiple ways.

  1. Add a Robots.txt file
  2. In your included file add a key variable for authentication.

1- Robots.txt:
Save this as Robots.txt in your website's root directory.

User-agent: *
Disallow: /elements

Save your files in elements folder. Whatever will be in elements folder, Google and other search engines's Crawler will not crawl it. This will never list in search results.

2- Use Key Authentication index.php will looks like this:

>

<div id="wrapper">
     <?php $key = 'allow_this'; ?>
    <?php include_once ('header.php'); ?>
     <div id="content">
        <h1>Title</h1>
         <p>Page content</p>
     </div> </div>

header.php looks like this:

<?php if($key=='allow_this'){ ?>
<div id="header">
    <ul class="menu">
        <li>
            <a href="/">Home</a>
        </li>
        <li>
            <a href="#">About</a>
        </li>
        <li>
            <a href="#">Contact</a>
        </li>
    </ul>
</div>
<?php } ?>