1

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!

designarti
  • 609
  • 1
  • 8
  • 18
  • I wouldn't worry about using the identical header on different sites, that doesn't count to the actual content. – Gerald Schneider Jan 22 '16 at 09:11
  • thanks, sounds fair.... as i said, is a thin theory – designarti Jan 22 '16 at 09:17
  • For security alone you should hide your source files outside of the web directory, (httpdocs, http_public, web), Only the bootstrap (index.php) and frontend assets need be visible to anyone outside. Even then, ìndex.php should be disguised as index.html, just to help keeping them guessing. – Flosculus Jan 22 '16 at 09:18
  • So I should put those file outside public_html? In the root of my webserver? Would that generate some path issues? If my root stucture looks like this: root/public_html/DOMAIN/index.php, I should keep those files in the root and include them with – designarti Jan 22 '16 at 09:30

1 Answers1

1

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 } ?>