1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

cron job is missing my base url in the sitemap.xml file

Discussion in 'PHP' started by mandi007va, Apr 3, 2017.

  1. #1
    i have a plugin that create the sitemap.xml file for my website and if i run that from cron hourly it is creating the sitemap file with entries like
     http:///sitemap_subs.xml.gz
    Code (markup):
    ..... it is actually missing the baseurl.
    but if i run that from my website it create correctly with my base url
    SEMrush
    help me to run from my cron , do i have to run it as appache user if so please give me the cron statement example[/code]
     
    mandi007va, Apr 3, 2017 IP
    SEMrush
  2. mandi007va

    mandi007va Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    any help experts, i have to run the php every one hour, so if i run it through cron it will do the job is ease........so please anyone any hint to solve
     
    mandi007va, Apr 3, 2017 IP
  3. akhileshbc

    akhileshbc Active Member

    Messages:
    99
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #3
    Is it a Wordpress website?

    Can you please explain what you meant by this?

    If you mean that, the your PHP code in a particular file works when accessed directly?
    Say for example, the PHP file is: http://www.mysite.com/gen.php
    When accessed, it is generating the sitemap files?

    In that case, just add a cron job in your cPanel to run that file, every hour!

    The command would be like this: /usr/bin/php -q /home/your_username/public_html/mysite.om/gen.php

    Here's the screenshot:

    [​IMG]

    Hope it helps!

    Otherwise, please provide some more information so that we could share a better solution.

    Thank you
     
    akhileshbc, May 20, 2017 IP
  4. mandi007va

    mandi007va Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    yes i did the same /usr/bin/php -q /home/your_username/public_html/mysite.om/gen.php

    but when running from cron the output sitemap if run from cron is like

    http:///sitemap.xml  the website name is missing, it should be like http://domain.com/sitemap.xml
    Code (markup):
     
    mandi007va, Jun 6, 2017 IP
  5. akhileshbc

    akhileshbc Active Member

    Messages:
    99
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #5
    I think that's path related issue. Check your code.

    Try defining a constant to store the base url and append it while generating the sitemap url data.

    Example:

    define('BASEURL', 'http://domain.com');  // your website base address
    
    //--------- while generating the sitemap data...
    
    echo BASEURL . '/index.php';
    echo BASEURL . '/contact.php';
    //...etc..
    PHP:
    See if it works.
     
    akhileshbc, Jun 6, 2017 IP
  6. mandi007va

    mandi007va Member

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #6
    my domain have sub domain so will setting only the main domain is enough or i have enter all the sub domains
     
    mandi007va, Jun 9, 2017 IP
  7. akhileshbc

    akhileshbc Active Member

    Messages:
    99
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #7
    You mean you are trying to include both the main domain's as well as subdomain's content in a single sitemap file?
    I think that wouldn't be a good choice! Have a look at this: https://webmasters.stackexchange.com/questions/82687/sitemaps-one-per-subdomain-or-one-for-the-base-domain

    I believe each base domain and subdomain has its own sitemap.

    That being said, if you want to include subdomain content in the code for creating sitemap file, just define that as a constant too.

    Example:

    define('BASEURL', 'http://domain.com'); // your website base address
    define('SUBDOMAINURL', 'http://abc.domain.com'); // your subdomain address
    PHP:
    Then use these constants while creating the links!

    Hope it helps.
     
    akhileshbc, Jun 9, 2017 IP