pecotamic / sitemap

Sitemap for Statamic v3
6 stars 9 forks source link

Protocol (https) bug? #3

Closed joseph-c-c closed 3 years ago

joseph-c-c commented 3 years ago

The plugin generates the /sitemap.xml with default HTTP protocol, even while the APP_URL in .env is set to HTTPS protocol, e.g. https://project-name.test.

It seems that there is no way to parse/manually overwrite the protocol to HTTPS in either the sitemap.blade.php or sitemap.php.

Is this a bug?

werner-freytag commented 3 years ago

The path of the sitemap is relative to your website. If your website is available with HTTPS, the sitemap is also available with HTTPS (as all your pages are).

joseph-c-c commented 3 years ago

The path of the sitemap is relative to your website. If your website is available with HTTPS, the sitemap is also available with HTTPS (as all your pages are).

Initially I also assumed so, by even after upload to production the sitemap.xml still generates http in the <loc>. This is a short extract from a website in production running in only https mode, with the npm run prod enabled server-side:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" 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/sitemap.xsd">
<url>
<loc>http://website-name.com</loc>
<lastmod>2021-01-06T08:56:35+00:00</lastmod>
<priority> 1 </priority>
</url>
<url>
...
werner-freytag commented 3 years ago

The <loc> entry uses the value of APP_URL. Did you change it in your production system?

joseph-c-c commented 3 years ago

The <loc> entry uses the value of APP_URL. Did you change it in your production system?

Yes. The APP_URL in .env is set to APP_URL=https://project-name.test, running locally in Valet.

Changing the APP_URL's protocol (switching between http and https) don't seem to have any effect.

werner-freytag commented 3 years ago

Maybe a caching issue?

joseph-c-c commented 3 years ago

I have tried:

php please stache:clear
php please static:clear
php artisan config:cache

And also:

php artisan clear-compiled
composer dumpautoload

Without any luck. Am I missing anything? Normally the changes in .env get updated as they are saved, and I know for sure the .env file works as e.g. APP_KEY and other parameters are set and read by the production server.

werner-freytag commented 3 years ago

What's the config in your sites.php? In my case it is

    'sites' => [

        'default' => [
            'name' => '...',
            'locale' => '...',
            'url' => env('APP_URL', 'https://.../'),
        ],

    ],
joseph-c-c commented 3 years ago

Thanks maybe it, currently looks like:

'sites' => [

        'default' => [
            'name' => config('app.name'),
            'locale' => 'en_US',
            'url' => '/',
        ],

    ],

Let me test it out and get back to you

joseph-c-c commented 3 years ago

Findings:

  1. Setting APP_URL to https://project-name.test without changing the default 'url' => '/' in sites.php don't have an effect.
  2. Changing project's url parameter to 'url' => env('APP_URL', 'https://domain-name.com'), which require that you run valet secure and then valet restart commands and accessing the site locally as "insecure", will work locally with protocol https, but in production the https://domain-name.com homepage throws an 404 error page, while the https://domain-name.com/sitemap.xml correctly shows the <loc> in https. Catch 22 !

Note: https://project-name.test in Valet is different from domain name https://domain-name.com.

werner-freytag commented 3 years ago

So this seems to be a project configuration issue. This extension just uses the given URLs provided by statamic.