I would like to add the trailing slash in general when it is absent in the request URL:
when user requests
https://example.com/blog
, it should be redirected tohttps://example.com/blog/
when user requests
https://example.com/abc.jpg
, it should be served as it is
When the server is Apache
, it seems it is usually done by mod_rewrite
. Unfortunately, our system include a CDN
(AWS CloudFront
) which causes problem when use mod_rewite
: the request will be redirected to the origin server, and the URL in the browser changes to origin server's URL.
I also tried mod_alias
's RedirectMatch
. But it seems it is too difficult for regular expressions to accomplish complex match patterns (in fact, it needs regex not match pattern).
So how to add the trailing slash in general for an Apache
+ CDN
architecture?
Edit:
Thanks to Michael, it turns out that whitelist the Host header in CloudFront solves my problem: the redirected URL remains the same as the old one (with slash).