开发者

Dynamic PHP website with MySql database; How to create a sitemap for this?

开发者 https://www.devze.com 2023-01-30 12:16 出处:网络
I have a classifieds website. The website is php based, and uses a mysql database. Today, I have a sitemap which I have to update using an external php script.

I have a classifieds website. The website is php based, and uses a mysql database.

Today, I have a sitemap which I have to update using an external php script. This php script takes all classifieds from the database and creates an xml sitemap, fresh.

Problem is I have to do this manually, by first opening the php script, then waiting for it to complete, then submitting the sitemap to google again (even though the开发者_运维百科 last step is optional I still do it).

I must also point out that even though I do submit this to google, it still isn't indexed (doesn't come up in the search results), which I want it to.

I want the classifieds to show up in google SERPS as soon as possible. Currently this is taking too long... Like a week or so.

Anyways, I need to know how to improve this method I have. Should I open and write to the xml file on every new classified?

I hesitat to do that because this means the file is open almost all the time, because new classifieds are frequent, and sometimes there are several new classifieds at the same time, so how would this impact the opening and writing to file if the file is already in use etc etc...

Is there any other method, like submitting a php sitemap to google, and whenever google accesses this php file, a new xml is dynamically created?

Need some ideas on how to do this in best way please...

Also, question 2:

If I dont have any links to a specific page on my server, except for a link in a sitemap, will this page be indexed anyways?

Thanks


You are asking too much from Google. They aren't magic. Indexing the whole internet is a big task. And they aren't out there to do what you want. However, there are ways to get the google to notice things fasterish and also ways to get more up-to-the-moment searching through other means.

Step one. The xml sitemap is good, but it still helps to have a legit html everything-everywhere link list/map. This is because links are in general of higher importance than a site map. So many search engines get to them faster.

On that note, not being the only dood linking to your stuff is a HUGE help. The way indexing works means that getting on the list sooner means being updated in the google sooner. More links from outside means more points of entry.

Also, the way google determines how important your site is comes, in part, from how much others link to you. More importance means being crawled for new info more often.

Now, about real time search. The 'next big thing' in search is using real time items to get more relevant results. Google already is doing some of this for certain things. Sports, big events like the recent spacex launch, so on. They are using Buzz and Twitter. Others are using facebook and a few other services.

Encouraging your users to tweet/like your items can make you more real-time search-able. So the moment a new listing comes out, a bunch of links may show up on twitter, and then they are more likely to show up in a real-time search.


You could put the script that builds the sitemap in the logic loop that creates a new classified ad. That way every time a new ad is created, the sitemap is updated.

Google has advice on using HTTP ping service to submit the sitemap automatically. You can use PHP's Client URL Library to create the ping.

Finally, you're out of luck trying to get Google to index your pages faster. As they say in their Webmaster Guidelines (in the sitemap section):

Google doesn't guarantee that we'll crawl or index all of your URLs.

In short: until Google's algorithm starts to believe your website is HotShitTM, they won't index every URL, and will usually take their time about it, sitemap or not.


I have created a small sitemap for the Laravel website. Since its an MVC arch structure remains the same.

Routing part:

Route::get('/sitemap', ['as' => 'Sitemap index', 'uses' => 'SiteMapController@index']);
Route::get('/sitemap/page', ['as' => 'Sitemap page', 'uses' => 'SiteMapController@page']);

View part two files Index.php this will be main sitemap index file

 <?xml version="1.0" encoding="UTF-8"?>
   <sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  
    <sitemap>
    <loc><?php echo url('/') ?>/sitemap/page</loc>
    <lastmod><?php echo date('c', time()); ?></lastmod>
</sitemap>
<sitemap>
    <loc><?php echo url('/') ?>/sitemap/exchanges</loc>
    <lastmod><?php echo date('c', time()); ?></lastmod>
</sitemap>

page.php this is accessory files for individual urlset

<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<?php foreach ($posts as $post) { ?>
    <url><loc><?php echo url('/') ?>/<?php echo $post['uri']; ?></loc><lastmod><?php echo $post['time']; ?></lastmod> <changefreq><?php echo $post['freequency']; ?></changefreq>
        <priority><?php echo $post['priority']; ?></priority>
    </url>
<?php } ?>
</urlset>

Now, controller, where you run the show:SitemapController.php you can change the time based on the frequency and freshness of the updates you provide in the content.

  class SiteMapController extends Controller {

    public function index() {
    return response()->view('sitemap.index')->header('Content-Type', 'text/xml');
     }

 public function page() {
    $posts = array(
        array("uri" => "", "time" => date('c', time()), "freequency" => "Daily", "priority" => "0.8"),
        array("uri" => "about-us", "time" => "2018-08-17", "freequency" => "Monthly", "priority" => "0.5"),
        array("uri" => "contact-us", "time" => "2018-08-17", "freequency" => "Monthly", "priority" => "0.5"),
        array("uri" => "privacy-policy", "time" => "2018-08-17", "freequency" => "Monthly", "priority" => "0.5"),
        array("uri" => "cookie-policy", "time" => "2018-08-17", "freequency" => "Monthly", "priority" => "0.5"),
        array("uri" => "thank-you", "time" => "2018-08-17", "freequency" => "Monthly", "priority" => "0.5"),
    );

    return response()->view('sitemap.page', ['posts' => $posts])->header('Content-Type', 'text/xml');
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消