Skip to content

Commit bbc8abb

Browse files
committed
Fix error when a sitemap path starts with //
When creating a Psr7 request with a base_uri set in the Client and a path that starts with // (like '//wp-sitemap.xml'), the path is interpreted as an absolute URL and we get a ClientException for 'unknown host: wp-sitemap.xml'. This is fixed by removing base_uri from the client and always making Requests with the full url. This was discovered while debugging #824 and may address that issue.
1 parent 10ba290 commit bbc8abb

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- add ability to rewrite hosts specified on a new advanced options page @john-shaffer
99
- as part of this, changed the host replacement function to use strtr instead of str_replace to avoid replacing things that we just replaced
1010
- add advanced option to skip URL rewriting @john-shaffer
11+
- fix error when a sitemap path starts with // @jhatmaker, @john-shaffer
1112

1213
## WP2Static 7.1.7
1314

src/DetectSitemapsURLs.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public static function detect( string $wp_site_url ) : array {
3939

4040
$client = new Client(
4141
[
42-
'base_uri' => $base_uri,
4342
'verify' => false,
4443
'http_errors' => false,
4544
'allow_redirects' => [
@@ -70,7 +69,7 @@ public static function detect( string $wp_site_url ) : array {
7069
}
7170
}
7271

73-
$request = new Request( 'GET', '/robots.txt', $headers );
72+
$request = new Request( 'GET', $base_uri . '/robots.txt', $headers );
7473

7574
$response = $client->send( $request );
7675

@@ -106,7 +105,7 @@ public static function detect( string $wp_site_url ) : array {
106105
$sitemap
107106
);
108107

109-
$request = new Request( 'GET', $sitemap, $headers );
108+
$request = new Request( 'GET', $base_uri . $sitemap, $headers );
110109

111110
$response = $client->send( $request );
112111

0 commit comments

Comments
 (0)