Omit index.html in Cloud Front

How to access index.html in subdirectories with Cloud Front by omitting the file name I was stuck when I published S3 with wordpress static files on the web and it didn’t see the index.html in the subdirectory Cloud Front + S3 with CDN and SSL support for web publishing is appealing. If you can publish a site that doesn’t fall down smoothly, that would be the only way to get the job done.

What we want to do

When I wanted to see the “" file, I wanted to see the “ I wanted “grammar/" to automatically look at the index.html file. since WordPress places Index.html in each permalink directory by default, I didn’t want to do it by stating index.html after I made it static, so I looked for a way I searched for a way to do this.

Redirect by function

CloudFront allows you to select a function in addition to a distribution. We decided to write a program that will automatically write index.html at will by selecting a function from the tab.

Proceed with the creation of the function and include the following code in the development tab

function handler(event) {
    var request = event.request
    var uri = request.uri;
    if (uri.endsWith('/')) {
        request.uri += 'index.html';
    } else if (!uri.includes('.')) {
        request.uri += '/index.html';
    return request;

Click on Publish Function and Add Associations and select the distribution to which you wish to automatically grant index.html.

This is the end of the configuration, so when you access the “Distribution Domain Name", you will automatically be able to access the site that requires index.html.


We have introduced some of the problems we encountered when publishing a web server with Cloud Front, and how to make WordPress static and publish websites with Cloud Front + S3 for blazing speed. Please read it as well if you like.

Follow us on Twitter if you like.