How we integrate .html link for pages?

Hi Friends,

I have created site in frontity with wordpress API.

Every think is working fine but as per my client website working in .html link for wordpress site.

I have completed all website without .html link but after add .html link i have faced error in API call.

I have setup one demo and checked this one issue then i am facing below error .

kindly check this one error link :

Then console API error,

"/about-us.html/": Object { isError: true, isReady: true, isFetching: false, … }
errorStatus: 404
errorStatusText: "post type from endpoints \"posts,pages,media\" with slug \"about-us.html\" not found"
is404: true
isError: true
​​isFetching: false
​isReady: true
link: "/about-us.html/"
page: 1
query: Object { }
route: "/about-us.html/"

Please help me how we resolve this error.

Hi @bhagvan.vrinsofts

The link needs to be a valid slug, and “/about-us.html/” is not a valid slug. The period . is disallowed in slug names.

A slug should consist only of lowercase alphanumeric characters [a-z, 0-9], dashes -, and underscores _. In addition the following rules apply: you cannot have two or more dashes in a row, however sequences of underscores are permitted, and a slug cannot start or end with a dash.

HI @mburridge ,

I have used valid slug.

When i have used without .html then it’s working fine. but i will use .html in after url then facing above error.

I have added below code in index.js for .html link ::

Please help me how we will use with .html link for pages.

Thanks.

Hi @bhagvan.vrinsofts ,

Can you please provide a repo or code-sandbox with your code? This is especially helpful to find solutions to technical issues with specific code

Detailing the info suggested here when having issues will help the community to provide the best possible help as quickly and as efficiently as possible.


Have you checked the following post ?

It goes about the same issue and some solutions are provided (specially this one by @luisherranz )

1 Like

Hi @juanma ,

Thanks for reply me.

Actually I have already finished my site without .html url. so i have question for i think i will add .html url then any effect for my current code or API.

Thank you.

HI @juanma and @all ,

I have completed my project only this point is pending. so please any one help me…

I have uploaded my code in github and attached below link.

I have added code for .html in index.js file.

 init: ({ libraries }) => {
        libraries.source.handlers.map((handler) => {
          handler.pattern += "/(.*)?/:slug(\.html)?";
          return handler;
        });
      },

But Still i am facing below error.

Can you please help me for this.

Thank you.

Hi @all

I have resolved issue.

 init: async ({ libraries }) => {
 		  const { handlers } = await libraries.source;
 		  //const postTypeHandler = handlers.find((h) => h.name === "post type");
 		  libraries.source.handlers.push({
           name: "post type",
           priority: 20,
           pattern: "/(.*)?/:slug.html", // post or page or attachment
           func: postTypeHandler({
             // Those are the default endpoints plus "product"
             endpoints: ["pages"],
           }),
         });