简体   繁体   中英

Do search engines have trouble with urls like somesite.com/index.php?page=photos

I'm new to php coding, web development, and search optimization - so newbie overall. In the process of learning php and web development I've been trying out different website architectures and layouts. One I'm working on uses an approach like the following:

I have one index.php page which always loads a header.php, sidebar.php, and footer.php. The index.php also contains a switch so that depending on the page variable the index.php is passed it loads different core content. So for example a examplesite.com/index.php?page=photos and examplesite.com/index.php?page=stories would both have the same header, footer, and side bar but one would have photos and one would have stories as the main content.

<?php $page = $_GET['page'];?>

<?php include("header.php"); ?>
<?php include("nav.php"); ?>
<?php 
      switch ($page)
      {
      case 'play':
        include("photos.php");
        break;
      case 'cards':
        include("stories.php");
        break;
      default:
        include("frontpage.php");
      } 
      ?>
<?php include("footer.php"); ?>

My navigation is made up of href="index.php?page=..." links so choosing a menu button on the index page essentially calls itself passing it the new core to load.

I have no idea if this is a totally unorthodox approach but it all started because I was initially going to create a wordpress theme but then halfway through decided not to do it in wordpress.

What i'm concerned about are what drawbacks could be associated with this approach when it comes to search engines, indexing, seo etc.

What are other drawbacks or issues I should be thinking about that maybe I'm not?

Thanks in Advance!

I have no idea if this is a totally unorthodox approach

There is nothing essentially "unorthodox" in using a query string to load various pages. Billions of sites using this approach. Search engines can index such pages all right.
Nevertheless,

I have one index.php page which always loads a header.php, sidebar.php, and footer.php.

This is wrong concept.
Having an index.php file only to load header and footer makes no sense and makes your site plainly unusable.

Here are main faults in your design:

  1. You're assuming that header.php would be called with the every page call. That's wrong.
  2. You're assuming that header.php will always be static. That's wrong.
  3. You forgot to create a template for the page itself.

The main rule everyone have to learn by heart:

Not a single character has to be sent into browser, until all data gets ready.

Why?

  • it's 2012 today. AJAX era. What if your code will have to send JSONed data instead of whole HTML page?
  • there is a thing called HTTP header . Sometimes we have to send them. And it's gets impossible if you already have your ornate HTML header sent.
  • Separating display logic from the business logic will let you use the same php code on many sites. You will have to change only templates and don't touch engine files. That's really great benefit.
  • Imagine you're going to make a custom <title> tag for your pages, based on the page content. Isn't it extremely common thing? But you can't make it without using templates.

So, you have to have one common site template containing header and footer and also dedicated templates for the every php script.
And these templates have to be called only when all business logic is done - ie you have got all your data ready.

An example layout is going to be like this:

.1. page itself.

it outputs nothing but only gathers required data and then calls a template:

<?
//include our settings, connect to database etc.
include dirname($_SERVER['DOCUMENT_ROOT']).'/cfg/settings.php';
//getting required data
$DATA=dbgetarr("SELECT * FROM links");
$pagetitle = "Links to friend sites";
//etc
//and then call a template:
$tpl = "links.tpl.php";
include "template.php";
?>

.2. template.php which is your main site template,

consists of your header and footer:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My site. <?=$pagetitle?></title>
</head>
<body>
<div id="page">
<? include $tpl ?>
</div>
</body>
</html>

.3. and finally links.tpl.php is the actual page template:

<h2><?=$pagetitle?></h2>
<ul>
<? foreach($DATA as $row): ?>
<li><a href="<?=$row['link']?>" target="_blank"><?=$row['name']?></a></li>
<? endforeach ?>
<ul>

this way you'd need no index with includes at all

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM