PEAR Articles

  Home arrow PEAR Articles arrow Page 5 - Managing robots.txt using PHP: Generat...
PEAR ARTICLES

Managing robots.txt using PHP: Generating Dynamic Syntax
By: Codex-M
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2010-07-14

    Table of Contents:
  • Managing robots.txt using PHP: Generating Dynamic Syntax
  • Robots.txt using PHP example
  • Creating the PHP file and the static syntax
  • Upload the complete myrobots.txt.php to the website's root directory
  • Revise .htaccess to rewrite myrobots.txt.php to robots.txt

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    Managing robots.txt using PHP: Generating Dynamic Syntax - Revise .htaccess to rewrite myrobots.txt.php to robots.txt


    (Page 5 of 5 )

    This is the standard .htaccess file for WordPress,

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /index.php [L]

    </IfModule>

    You need to add this rewrite rule to the existing .htaccess lines:

    RewriteEngine On

    RewriteRule ^robots.txt$ /myrobots.txt.php

    So it will look like this:

    This rewrite rule will basically assign the contents of myrobots.txt.php to robots.txt.

    You will need to upload the .htaccess to the root directory of your server, in the same path as with the myrobots.txt.php file.

    Implementation Technique

    It is important to note several important points when implementing this project.

    Do not remove or delete the old robots.txt file; it should still reside in the server root directory. It is okay to erase all the contents of the old robots.txt file, but never delete it.

    Therefore the following files must be in the server root directory for this method to work:

    a. .htaccess - this contains the rewrite rule from myrobots.txt.php to robots.txt

    b. "old" robots.txt - this is the old robots.txt file which you were using previously (before you started using PHP to generate syntax).

    c. myrobots.txt.php - this is the actual script that generates the robots.txt syntax.

    A full sample implementation of this project can be seen at http://www.php-developer.org/robots.txt . The robots.txt is dynamically generated using PHP, as indicated by these comments in the robots.txt syntax:

    # Start of dynamically generated robots.txt syntax

    Disallow: /2009/

    Disallow: /2010/

    # End of dynamically generated robots.txt syntax

    Finally, for safety reasons, it is recommended that you use another name for the PHP file generating your syntax, and not the one used in this tutorial, which is myrobots.txt.php


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    PEAR ARTICLES ARTICLES

    - Installing PEAR
    - PEAR: an Introduction
    - Managing robots.txt using PHP: Generating Dy...
    - Deleting Authors from a PEAR Content Managem...
    - PEAR CMS: Index and Delete Scripts
    - Listing Articles for a PEAR Content Manageme...
    - Building an Authors Page for a PEAR CMS
    - Building the View Details Page in a PEAR CMS
    - Creating the Main Pages of a PEAR CMS
    - Completing the Login Script for a PEAR CMS
    - User Authentication for a PEAR CMS
    - A PEAR CMS: Examining the Code
    - Building a Content Management System with PE...
    - Installing a PEAR Package
    - My PEAR: The Beginning


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap