Skip to content

Commit b9abcd9

Browse files
committed
Force trim slashes
1 parent 9f80816 commit b9abcd9

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Release Notes for Blitz CloudFront Purger
22

3-
## 4.1.3 - Unreleased
3+
## 4.1.3 - 2025-03-12
44

55
### Fixed
66

77
- Fixed a typo in the field instructions on the plugin settings page ([#14](https://github.com/putyourlightson/craft-blitz-cloudfront/issues/14)).
8+
- Fixed a bug in which base site URLs containing sub-paths were not being purged ([#15](https://github.com/putyourlightson/craft-blitz-cloudfront/issues/15)).
89

910
## 4.1.2 - 2024-10-18
1011

src/CloudFrontPurger.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public function purgeSite(int $siteId, callable $setProgressHandler = null, bool
128128
}
129129

130130
$path = $this->getPathFromUrl($site->getBaseUrl());
131-
$path = rtrim($path, '/');
132-
$this->sendRequest([$path . '/*']);
131+
$wildcardPath = rtrim($path, '/') . '/*';
132+
$this->sendRequest([$path, $wildcardPath]);
133133
}
134134

135135
/**
@@ -255,9 +255,13 @@ private function getPathFromUrl(string $url): string
255255
$encodedReservedCharacters = ['%3B', '%2F', '%3F', '%3A', '%40', '%3D', '%26', '%2A'];
256256
$path = str_replace($encodedReservedCharacters, $reservedCharacters, urlencode($path));
257257

258-
// Append a trailing slash if `addTrailingSlashesToUrls` is `true`.
258+
// CloudFront treats URLs with and without trailing slashes as distinct.
259+
// https://github.com/putyourlightson/craft-blitz-cloudfront/pull/15
260+
$path = rtrim($path, '/');
261+
262+
// Append a trailing slash if `addTrailingSlashesToUrls` is enabled.
259263
if (Craft::$app->config->general->addTrailingSlashesToUrls) {
260-
$path = rtrim($path, '/') . '/';
264+
$path = $path . '/';
261265
}
262266

263267
return $path;

0 commit comments

Comments
 (0)