I have swtiched my site from http to https but the problem is that sitemap is still showing http in the urls. How can I get sitemap to show the https urls.

Regenerating the xml file did not fix this problem.

Thank you.

CommentFileSizeAuthor
#7 defaultURL.PNG3.62 KBTentaculitis

Comments

tepelena created an issue. See original summary.

gbyte’s picture

Version: 8.x-2.8 » 8.x-2.x-dev
Category: Bug report » Support request

Please open up issues against the dev version next time.

As a quick fix I would suggest to use the 'base url' setting in the sitemap settings, there you can set the link base URL including https like so https://your-domain.com.

I do not have a SSL setup ATM to investigate properly, but the Drupal methods used in simple_sitemap should be generating https links themselves. - maybe your Drupal SSL setup is not correct?

gbyte’s picture

Status: Active » Closed (works as designed)

Closing due to lack of response.

bwinett’s picture

Status: Closed (works as designed) » Active

We are having the same issue. You can see it here: https://www.tek.com/sitemaps/1/sitemap.xml

Previously, we had left the default base url blank. But even after changing it to https://www.tek.com, as recommended in a previous comment, it remains the same.

Anyone know what "maybe your Drupal SSL setup is not correct" means?

gbyte’s picture

\Drupal\Core\Url generates URLs according to the current scheme used. If you set your environment according to this, https links should show on the sitemap.

bwinett’s picture

I don't see anything on that page that would help us. Our D8 site is fully HTTPS, and it's working great. But our sitemap files point to HTTP.

Tentaculitis’s picture

StatusFileSize
new3.62 KB

in xmlsitemap (Drupal 7) you can change the Default base URL setting to https://
Example:
Default base URL

gbyte’s picture

@Tentaculitis @bwinett You can do the above in simple_sitemap as well. Seems a bit like a workaround, but should work.

gbyte’s picture

Status: Active » Closed (works as designed)

Closing this. If you find guys find a way to make it always recognize https without setting base URL, make sure to open up a feature request along with a patch (if possible).

gbyte’s picture

gbyte’s picture

Status: Closed (works as designed) » Fixed
gbyte’s picture

Status: Fixed » Closed (fixed)
gbyte’s picture

I have tested it and it should work without any workaround. Maybe your base URL setting was in fact the problem and removing it (or changing to https as described above) fixes the issue.

jascote’s picture

I was having a similar issue.

Our SSL is terminating upstream from Drupal (we're using a load balancer and varnish). When the sitemap is being generated, Drupal's paths are still http. The simple sitemap module conveniently provides an opportunity to alter your links prior to generating the sitemap chunks, so in a custom module I was able to force https using the code below.

function my_custom_module_simple_sitemap_links_alter(array &$links) {
  foreach ($links as $key => $link) {
    $url = preg_replace('/^http:/', 'https:', $link['url']);
    $links[$key]['url'] = $url;
  }
}
gbyte’s picture

@jascote Would using the module's base_url setting not be an easier approach?

jascote’s picture

@gbyte.co That only worked for changing the sitemap index page. The elements on the individual sitemap pages were still being written as http. As far as I could tell in the SitemapGenerator.php, the base_url value isn't used in the individual sitemap chunks.

The getCutsomBaseUrl() function is only used in the generateSitemapIndex() function. generateSitemapChunk() isn't looking for a custom base_url, it's just processing through the links.

So adding a base url would fix the links on https://mydomain.com/sitemap.xml but on https://mydomain.com/sitemaps/2/sitemap.xml it was still http.

That's why I took the approach I used.

gbyte’s picture

@jascote

There is UrlGeneratorBase::replaceBaseUrlWithCustom() which is used in several methods across UrlGeneratorBase responsible for returning links. So All links returned through the default generator set should adjust to the custom base URL. Maybe you experienced a caching issue? In 2.x chunks were still heavily cached.

I advise to use 3.x anyway; if you are not using custom code, there is a smooth upgrade path from 2.x.

a.milkovsky’s picture

I can reproduce the issue.

My environment:

  • docker with Lando
  • the website is multilingual with multiple domains.

#7 base_url did not help me. I still see http links.

I am using a little bit extended version of #14 as a workaround for alternate_urls:

function my_custom_module_simple_sitemap_links_alter(array &$links) {
  foreach ($links as $key => $link) {
    // Fix the protocol for links in xml sitemap.
    $url = preg_replace('/^http:/', 'https:', $link['url']);
    $links[$key]['url'] = $url;

    // Fix the protocol for translation links in xml sitemap.
    foreach ($link['alternate_urls'] as $language => $alternate_url) {
      $alternate_url = preg_replace('/^http:/', 'https:', $alternate_url);
      $links[$key]['alternate_urls'][$language] = $alternate_url;
    }
  }
}
gbyte’s picture

@a.milkowsky If your Drupal setup is correct the module produces https links. Adjusting the base URL in the settings to 'https://your-domain.com' should work regardless of your setup as it does a simple text replace. Please double check.

akalam’s picture

I can reproduce the issue as well. When regenerating the sitemap from UI it uses the base_url and works as expected, but when regenerated via cron it gets changed back to http

alina.basarabeanu’s picture

Category: Support request » Bug report
Priority: Normal » Major

Our website has multiple domains and we left the default base URL empty as we do not want to generate the extra sitemap domains under the main one.
The links in the sitemap are generated with HTTP even if there is an SSL setup.
Please reopen the issue.

gbyte’s picture

Category: Bug report » Support request
Priority: Major » Normal

Guys this issue is for the unsupported 2.x version. If you experience this in 4.x, please update the issue accordingly and provide a step-by-step guide so I can reproduce - if possible on simplytest.me.

uri_frazier’s picture

I know this is an old issue, but thank you @a.milkowsky for your solution. It works fine on version 4.1.9