Search Engine Optimizing PHP Scripts

PHP pages have a reputation of being more difficult (or at least different) to SEO than static HTML pages. Here is an overview of the major issues encountered when trying to optimize PHP script for search engines. While this focuses on PHP much of it is still relevant to SEO ing dynamic pages in general.

PHP Speed

While page size does affect load time, spiders run on servers connected to high bandwidth networks, so download time is less important than the latency of the PHP script execution time. If a search engine spider follows a link on a site and is forced to wait too long for the server to process the PHP code behind that page, it may label your page as unresponsive.

The biggest delays in a PHP script typically are the database and loop code. Avoid making SELECT * calls, instead explicitly name all the columns you want to retrieve, and if you are using MySQL, test your queries using the EXPLAIN statement. To optimize loops consider using duplicated code instead of loops that don’t repeat very many times, also use as many static values, such as count($array) values inside the loop as you can, generating their values before the loop once.

Use of Compile Cache

The execution times can be improved by implementing compile caches like Turk MMCache ( or APC as a php module. Though I do agree, that these would not be sufficient where contents are changing dynamically or across time.

Clean URL

A major goal in SEO’ing your PHP pages, is to make them look and act like static pages. If you have a large site you can use Apache to fake static looking URLs, or, with a smaller site, you can simply keep your GET variables to a useful minimum. In either case, however, never allow a spider to see links with different URL having the same content. If the URL is different, the page should be too.

One of the major problems most webmasters have with getting their dynamic pages to index is URL cleanliness. Since many dynamic pages are created with GET variables, lots of pages have URLs that look like:


Most of the search engines will be able to follow this link, because it has 3 or under get variables (a good rule of thumb is to keep the number of GET variables passed in the URL to under 3), but any more than 3 variables and you will run into problems. Try using less GET variables, and make them more relevant, rather that useless id numbers use titles, and other keyword rich bits of text. This is an example of a better URL:


If the page requires more variables you may want to consider combining the variables by delimiting them with a hyphen or another unused character, and then splitting the variable in the server side script.

Disabling Trans_sid

Possibly the biggest cause of webmaster frustration when SEO ing php pages is presence of PHP session id numbers to links if cookies are rejected by the browser (Search engine spiders reject cookies). This will happen by default if your PHP installation was compiled with the enable-trans-sid option (and this is the default from version 4.2 onward), and it creates links with an additional, long nonsense looking GET variable. In addition to making the links clunky this gives spiders different URLs with the same content, which makes them less likely to treat the pages individually, and possibly not even index them at all. A quick way to fix this is to disable the trans-id feature, if you have access, in php.ini by setting session.use_trans_sid to false. If you dont have access to php.ini you can add this line to the .htaccess file in your root directory:

php_flag session.use_trans_sid off

Masking dymamic URLs

However the mere presence of a question mark in the URL will introduce a delay in google’s indexing of the page. This is referenced in the Interview with Daniel Dulitz of Google by Mike Grehan :

So the mere presence of a question mark in the URL doesn’t throw us for a loop at all. We will crawl those pages more slowly than we do with pages without question marks in the URL. Purely because they’ve identified themselves as being dynamic and we certainly don’t want to bring anyone’s site down because we’re hitting the database too hard.

Small sites will not need to worry much about this delay as it means your server is hit every few minutes, not a few times a second, but for larger sites this can slow down your sites inclusion into the index.

Making dynamic pages look static without mod_rewrite

A way to mask bulky dynamic page URLs (and avoid the question mark delay) is Apache directive ForceType in combination with a PHP command to interpret URLs like: as referring to a page called computers which is executed as a PHP script. This can be accomplished by inserting a line like this into the .htaccess file in the root of your web documents directory:
ForceType application/x-httpd-php
Once this is done, you can upload the computers.php without the extension ie simple computers. Inside computers you can use process the $_SERVER[‘REQUEST_URI’] to get the proper parameters.
function processURI() {
$request = explode("/",substr($_SERVER["REQUEST_URI"],1));
$count = count($request);
for (
$i = 1 ; $i < $count ; $i++) {
$values["arg".$i] = $request[$i];

Advantages of PHP in SEO

A great advantage to using dynamic pages as opposed to static pages is the ability to create content that is constantly changing and updated in real time. RSS headlines, randomly circulating content and other automated fresh content can boost your ranks in Google, and many other engines.

Another advantage to using PHP is that you can make simple modifications to many scripts to create relevant and fresh page titles. Since this is the most important on page factor in SEO special attention should be given to creating title tags that accurately reflect the current page content. Any html templates used in PHP pages can be altered to contain this line:

<title><?php echo $page_title?></title>

With this, $page_title can be set to a keyword rich text describing the page. Title text is also important in improving the click-through from SERP, so be sure that the title tags doesnt read like spam, but more like a human created title.