Loading PHP Pages Dynamically For On-page SEO

8 replies
I am my second week into learning PHP & building database-driven dynamic websites.
I noticed that some database-driven websites seem to load their pages from the database
into the main "index.php" page. In terms of on-page SEO & link indexing, is this the best way
to load the pages on your site & get them indexed by Google, Yahoo, Bing, etc., or should I
create separate page files (e.g. Home.php, About.php, Contact.php, etc.) for each page of my
website? Whichever is best in terms of SEO, I am willing to try it. Thanks.


P.S.
Oh, & the website that I'm building is an eCommerce website for my fiance. Would like for
the users to be able to click on any product & then load the corresponding details page about
the product either on that index page or on a separate page. Thanks again! :-)
#dynamically #loading #onpage #pages #php #seo
  • Profile picture of the author David Beroff
    I've had the exact same question/concern when I see sites where multiple pages of content all appear on the same URL. Search engines associate one URL with one set of content, so it would seem that the best approach would be to use traditional pages with independent URL's. (Note, I am only basing this on my gut, not on anything that I've observed or measured!)

    There are other benefits, as well, of course. If someone wants to share your content, they're going to grab the URL. If it's all the same, then the recipient won't see the content that the original person intended.

    In fact, I'm not entirely sure why people do use the single URL approach. Maybe they learned AJAX and thought it'd be cool to use it for everything?
    Signature
    Put MY voice on YOUR video: AwesomeAmericanAudio.com
    {{ DiscussionBoard.errors[10643299].message }}
    • Profile picture of the author MarketingAce
      Thanks for your reply David. Actually what I meant is for example:

      mysite.com/index.php?ProductID=55
      mysite.com/index.php?ProductID=103
      mysite.com/index.php?ProductID=681
      etc.
      etc..

      This is how you usually load multiple pages onto 1 single index.php page. The URL's do not stay the same. So sharing each page individually would work. I'm just trying to figure which route I should take when forming the URL's for this one index.php file while querying the database. Thanks again for your input though.

      Originally Posted by David Beroff View Post

      I've had the exact same question/concern when I see sites where multiple pages of content all appear on the same URL. Search engines associate one URL with one set of content, so it would seem that the best approach would be to use traditional pages with independent URL's. (Note, I am only basing this on my gut, not on anything that I've observed or measured!)

      There are other benefits, as well, of course. If someone wants to share your content, they're going to grab the URL. If it's all the same, then the recipient won't see the content that the original person intended.

      In fact, I'm not entirely sure why people do use the single URL approach. Maybe they learned AJAX and thought it'd be cool to use it for everything?
      {{ DiscussionBoard.errors[10643321].message }}
  • Profile picture of the author David Beroff
    Oh, OK; yeah, that's slightly better.

    But for that, I'd use a bit of .htaccess fancy footwork to instead offer URL's like:
    mysite.com/55/Blue-widget-with-flanges
    mysite.com/103/Deluxe-3-speed-widget
    mysite.com/681/Turbo-widget-overnight-delivery
    Signature
    Put MY voice on YOUR video: AwesomeAmericanAudio.com
    {{ DiscussionBoard.errors[10643330].message }}
  • Profile picture of the author Ralph83
    The following is bad SEO as you'd want some keywords in your URIs:

    Originally Posted by MarketingAce View Post

    mysite.com/index.php?ProductID=55
    mysite.com/index.php?ProductID=103
    mysite.com/index.php?ProductID=681
    Like this (though the product IDs could be left out completely in the following example):

    Originally Posted by David Beroff View Post

    mysite.com/55/Blue-widget-with-flanges
    mysite.com/103/Deluxe-3-speed-widget
    mysite.com/681/Turbo-widget-overnight-delivery
    WordPress for example, is able to use things such as post and page IDs only internally (as query variables) and serve / redirect to SEO URIs without IDs in them using its own internal rewrite API (no htaccess code required).

    WP also uses a separate PHP file to dynamically serve pages and another PHP file to serve posts. In theory you could do all of this with just a single index PHP file. It's just a matter of preference (would you want all your code to reside in the index file or not).

    However... re WP, the index file is basically the core file / the "granddaddy", as it loads all the other files using a single PHP require. This one require basically triggers a chain reaction, loading all of the files that are required for a certain query (e.g. serve a blog post or page).

    This approach in fact creates one big index php file on the fly. Here's why: when using PHP require or include, the code from a required or included file is simply copied into the file that uses the require or include statement. So the PHP engine basically mashes code together dynamically. More on that here.

    Note that to search engines it's about what your users get to see (the end), not about how it's done internally (the means). In fact, SEs / outsiders shouldn't even be able to look into any PHP files that are on your server, as that would be really bad for security reasons.

    Also, I'd like to recommend that you download a copy of WordPress and see how WP is doing things. It's very interesting.

    To Conclude:

    The biggest reason NOT to put all your code in your index php file, is probably to reduce server load / page load times.

    For example: would WP consist out of one single index file, it would also load page code while a user is actually just requesting a blog post. Which is why the require and include statements are used, so only the code required to serve a blog post is loaded and not all the other code that is actually not required (e.g. the page code).

    I'm guessing that what you've seen is a site using ugly permalinks. Which, URI-wise, made it look as if that site consists out of one single index php file. Even though it's probably using a similar approach as WP (require / include statements).

    In fact, the WP rewrite API always references the index.php file internally. The end-user just doesn't get to see this on the front-end. This can be seen in the first code example here.

    In your specific case, I'd do the following:

    - Write an index file containing the front page code & HTML;
    - Write separate footer.php, header.php, home.php (not required as home is actually index.php), about.php, contact.php, product php files (one separate file for each product) etc.;
    - PHP require_once both footer.php & header.php into index.php, about.php etc.;
    - HTML link (a href) to home (index.php), about.php, contact.php etc..

    This is how I started 10+ years ago (building a small webshop) and it's the easiest approach. It doesn't require variables such as product IDs and thus no complicated URI rewrite code. While having a separate footer.php and header.php, gives you a chance to practise with dynamic code inclusion.

    You could then manually SEO each product php file (e.g. simply name it cool-green-bike.php) and use some basic SQL queries to query the database's product data of that green bike and dynamically load it into cool-green-bike.php.

    For the product data, you could manually create some SQL database tables, containing all the data you'd like to dynamically load into your webshop.

    Taking little baby steps is key here. Otherwise things will get too complicated very quickly and this will very likely cause you to abandon the entire project. Which happened to me a lot in the beginning: "Oh, I've got a great idea!" And then, sooner or later, I couldn't wrap my head around it anymore and moved on to the next project. You will learn to code when you make the same mistake as I did, just don't expect to finish a project the first few years

    In case you're looking to build a complicated webshop, with a shopping cart, dozens and dozens of products, then it's probably better to use WordPress or osCommerce as a starting point. Because I learned the hard way that building something complicated solo / without a dev team and from scratch, requires a pretty high level of insanity. It's like writing a book that has 1000s of pages... which only monks used to do and they chose to give their life away anyway / devote it to a higher power (no lost time there). So now I use WP as a starting point for my projects and customize the heck out of it.

    Stories like Zuckerberg building FB in just 1 night, are just that; stories I wouldn't be surprised if, in reality, he initially outsourced it to India (lots of start ups do that).

    I hope the above is of some use to you
    {{ DiscussionBoard.errors[10644036].message }}
    • Profile picture of the author David Beroff
      Originally Posted by Ralph83 View Post

      (though the product IDs could be left out completely in the following example)
      True, they could be left out, but now you'd be introducing a translation step. By keeping the identifiers in the URL, everything can be passed as ProductID under the hood, (i.e., with .htaccess), and essentially ignore the text after the slash altogether.
      Signature
      Put MY voice on YOUR video: AwesomeAmericanAudio.com
      {{ DiscussionBoard.errors[10644050].message }}
      • Profile picture of the author Ralph83
        Originally Posted by David Beroff View Post

        True, they could be left out, but now you'd be introducing a translation step. By keeping the identifiers in the URL, everything can be passed as ProductID under the hood, (i.e., with .htaccess), and essentially ignore the text after the slash altogether.
        I agree, it's indeed easier to keep the IDs in place, unless one is willing to write something similar to WP's rewrite API. In that case I'd just use WP as a starting point... why reinvent the wheel, right

        @ MarketingAce:

        The following might be useful to you:

        https://webmasters.googleblog.com/20...atic-urls.html
        {{ DiscussionBoard.errors[10644071].message }}
        • Profile picture of the author MarketingAce
          I appreciate the support, however, I can GUARANTEE you that I'm NOT going to switch to "WP". Depending on previous written code while trying to become your own Web Developer really takes the fun out of learning to code. I want to write my own code as to why I didn't choose to use WP like all of the other Internet Marketers who rely on it. I am a DIY type of person, so learning to code from scratch is what I'd LOVE to do.

          I have also written this same thread on other websites (including Web Developer forums) & most experienced Web Developers are all pointing in the same direction. Most of them are telling me to use .htaccess for rewriting the URLs & loading all of the content of each product into 1 index.php file. It actually didn't look like it required that much code to do it.

          I've also thought about using my own implementation by using a PHP string replace function to replace the empty spaces of the Title of each product to include a "-" in between each space after the user clicks on any product for "more details". Example:

          | ID: 333 | Title: Womens Gold Cuff Bracelet |

          http://mysite.com/index.php?ProductI...-cuff-bracelet

          OR

          | ID: 105 | Title: Mens Leather Bracelet |

          http://mysite.com/index.php?ProductI...eather-braclet

          What do you think about using the $_GET variable to capture the link that's clicked to then form it into the format about using a PHP str_replace() Function for each Title of the product to remove the spaces & replace them with dashes "-"?

          Would appreciate your input as you've already been very helpful. If not the replace method, I will consider using the .htaccess rewrite method. Thanks again! :-)



          Originally Posted by Ralph83 View Post

          I agree, it's indeed easier to keep the IDs in place, unless one is willing to write something similar to WP's rewrite API. In that case I'd just use WP as a starting point... why reinvent the wheel, right

          @ MarketingAce:

          The following might be useful to you:

          https://webmasters.googleblog.com/20...atic-urls.html
          {{ DiscussionBoard.errors[10644127].message }}
  • Profile picture of the author David Beroff
    First of all, it wouldn't be an either/or. You could (and should) use .htaccess with various title manipulation.

    You are on the right track as far as replacing spaces, but it's not just spaces that are of concern. I'm sure you can research to find out which characters can cause problems for URL's, but in a case like this, it's easier to use a simple rule to retain A-Z, a-z, 0-9, and just replace everything else with hyphens. (i.e., inclusive instead of exclusive) That'll make life far simpler than realizing (in the future) that you had missed a particular special case, and then having to deal with the possibility that someone's already pointing to the site with an illegal URL.

    More generally, learn about data sanitization and validation in PHP (and elsewhere). It's a bad practice to directly use any data entered by a person, even if they are a trusted administrator-type person. Much has been written about this, so I won't reinvent the wheel here.
    Signature
    Put MY voice on YOUR video: AwesomeAmericanAudio.com
    {{ DiscussionBoard.errors[10644157].message }}

Trending Topics