Follow this guide to make your PHP translated website SEO-friendly.

How To Use:

  1. Download "bablic.php" from the Github repository into your php index folder.
  2. Place this snippet at the top of your index.php file, if your website has header.php or head.php that is used in all pages, it might be the right place to put the code in.
<?php
// init the Bablic SDK with your site ID (required)
require 'bablic.php';
$site_id = 'your site id';
$bablic = new BablicSDK(
    array(
        'site_id'=> $site_id
    )
);

// run the SEO middlware
$bablic->handle_request(
    /*array(
        'debug' => false, //optional
        'nocache' => false, //optional
        'url' => 'http://some.url.com' //optional
   )*/
);

# Example: how to paste the snippet in your HTML for optimal performance
?>
<html>
   <head>
       <title>A most unique website</title>
       <?php echo $bablic->bablic_top() ?>
   </head>
   <body>
       A most unique content
       ....

And that's it, you can continue and click "Verify" in the Bablic SEO Configuration Wizard to validate the installation.

Options

site_id - required string, your Bablic site id.

nocache - optional boolean, when true does not use cache. Defaults to false

url - optional string, if you ever need to query Bablic for a different domain (testing, staging, etc)

Methods

handle_request() - request middleware, renders html optimized for crawling engines, only to crawling engines

bablic_top() - generates the snippet code to put in the page head tags. This method must be run anywhere inside the page <head> tag.

Sub-Directories

For SEO reasons, it is sometimes recommended to use sub-directory for each translated language (for example: http://example.com/fr, http://example.com/it)
To have your translated website work with language sub-directories you'll need to complete 2 steps:

Handle rewrite in your Apache/NginX configuration

Apache:

Add this code to your Apache configuration file or .htaccess file, and replace the language codes (de/es/it) with your own website language codes:

RewriteEngine on  	
RewriteRule ^(de|es|it)\b(.*)$ $2 [PT,QSA]

Nginx:
Add this location section above other your other location definitions, and replace the language codes (es/de) with your own website language codes:

location ~ ^/(es|de)/ {
      rewrite ^/(?:es|de)/(.*)$ /$1;
}

Reload the Apache/NginX process to force the server to run the new settings.

You can click the "Verify" button in your Bablic SEO Configuration Wizard to validate the sub-directory installation.

Did this answer your question?