Web Analytics Made Easy -
StatCounter How do I send a text file from my server? - CodingForum

Announcement

Collapse
No announcement yet.

How do I send a text file from my server?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I send a text file from my server?

    Hi,

    Because I am dynamically generating sub-domains and pages on them
    I want to update the sitemaps and provide a robots file for each sub-domain.

    Is this the correct way to send the robots.txt ?

    From my htaccess file I am expecting my robots.php script to run.


    SO ... a bot (or a browser ) looks for ... space-store.exampleX.com/robots.txt

    The htaccess file:

    # THIS IS SUPPOSED TO EXTERNALLY REDIRECT TO exampleZ.com

    # GETTING PLATFORM ROBOTS.TXT FILE
    RewriteCond %{HTTP_HOST} ^(.+).exampleX.com$ [NC]
    RewriteCond %{HTTP_HOST} !^www.exampleX.com$ [NC]

    RewriteRule ^robots.txt http://exampleZ.com/robots.php?s=exampleX.com&p=%1 [NC,QSA,L]



    The robots.php script


    PHP Code:
    <?php 
    /*  robots.php
    *
    *  Sends Robots txt file
    */
    require_once("my_functions.php");

    if(isset(
    $_GET["s"])){                         
        
    $site_url safe_sql($_GET["s"]);    // e.g. exampleX.com
        
    $plat_name safe_sql($_GET["p"]);   // e.g. space-store
        
        
    $robot_txt_name $plat_name.'.'.$site_url.'_robots.txt';   // e.g.  space-store.exampleX.com/robots.txt

        
    $length strlen($robot_txt_name);

        
    $robot_path "/home/examZ/public_html/robots/".$robot_txt_name;
        
        if (
    file_exists($robot_path)) {
            
    header('Content-Description: File Transfer');
            
    header('Content-Type: text/plain');
            
    header('Content-Disposition: attachment; filename='.$robot_path);
            
    header('Content-Transfer-Encoding: binary');
            
    header('Content-Length: ' $length);
            
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
            
    header('Expires: 0');
            
    header('Pragma: public');
            }
        else {
            echo 
    "The Robot txt file : $robot_path was not found.<br>";
            }    
        }
    exit;
    ?>
    Is this correct ?

    Many thanks.
    David.
    Last edited by jeddi; Sep 15, 2016, 12:51 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    I have just realised that I am not picking up the sub-domain name.

    I think I need to chane the '%' to a '$'

    The htaccess file:

    # THIS IS SUPPOSED TO EXTERNALLY REDIRECT TO exampleZ.com

    # GETTING PLATFORM ROBOTS.TXT FILE
    RewriteCond %{HTTP_HOST} ^(.+).exampleX.com$ [NC] // < --- trying to get the sub-domain from here
    RewriteCond %{HTTP_HOST} !^www.exampleX.com$ [NC]

    RewriteRule ^robots.txt http://exampleZ.com/robots.php?s=exampleX.com&p=$1 [NC,QSA,L]



    BUT is my script, the right way to do this ?

    Thanks.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

    Comment

    Working...
    X