Unable to access analytics.txt once uploaded, returns 404

I’ve been asked to add an analytics.txt file to a wordpress website so I’ve created the file and uploaded it to the server document root but when I go to it via the url www.examples.com/analytics.txt all I get is a 404 error.

I’ve checked the file permissions and I’ve cleared the wordpress cache but neither have helped.
Any ideas?

Read More

The folder structure is as follows:

wp-admin
wp-content
wp-includes
analytics.txt    <-- added this file, but cannot seem to access it via a web browser
index.php
etc...

Related posts

2 comments

  1. This is NOT the solution but it is a work-around while I carry on trying to figure out why wordpress won’t allow me to access my file.

    So if you’re desperate and HAVE to get it sorted right now, here is what you could do, but I warn you, it’s ugly! Open your index.php file and you should see something like this:

    <?php
    define('WP_USE_THEMES', true);
    require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    ?>
    

    Make a backup copy first and then add the wrapping if statement:

    <?php
    if ($_SERVER[REQUEST_URI] == '/analytics.txt') {
        die('Put the text that you were instructed to put into your analytics.txt file in here');
    } else {
        define('WP_USE_THEMES', true);
        require( dirname( __FILE__ ) . '/wp-blog-header.php' );
    }
    ?>
    

    Like I said, this is a dirty solution but when needs must and the client is getting impatient, this could help in the mean time.

    Hoping that someone will have a better solution though!

  2. I was able to get this to work with the following for the Sage theme:

    1. Upload the analytics.txt through the theme administration panel
    2. Copy the url of the upload and remove the hostname. For me it looked like this: app/uploads/2018/09/analytics.txt
    3. Open the functions.php file and add the following:

      function analytics_txt_rewrite(){
      
          add_rewrite_rule('^analytics.txt$','<route to your analytics.txt file>','top'); 
      } 
      add_action('init','analytics_txt_rewrite');
      
    4. Flush and regenerate the rewrite rules database: From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.

Comments are closed.