Jump to content

Add .html instand trailng slash


regesh
 Share

Recommended Posts

some quick options:

check for url segment 'news.html' off the root and then render the /news/;

for  'my-fist-post.html' you could grab the url segment in the /news/ template, explode it at the period and then use the first part to find and display the post.

you'd need to hardcode the links or do a hook on the page path to rewrite the URLs of the pages

  • Like 1
Link to comment
Share on other sites

6 minutes ago, regesh said:

but is there any option to automate it. such as "add .html to url" ?)))

No, there isn't. And there is no reasons to prefer .html endings to slash even from SEO point.

  • Like 6
Link to comment
Share on other sites

20 hours ago, Macrura said:

do a hook on the page path to rewrite the URLs of the pages

hooking into page path allows you to change that; so you can add .html if you want; you also need to code in some logic about what happens with directory indexes

Link to comment
Share on other sites

 

This isn't tested, but i use this general sort of thing all the time to change page URLs. It is within the hook function that you need to deal with your logic of when to add the .html and when not to, you will need conditional statements...

/**
 * This hook modifies the default behavior of the Page::path function (and thereby Page::url)
 *
 *
 */
wire()->addHookBefore('Page::path', function($event) {
  $page = $event->object;
  if($page->template == 'something') {
    $event->replace = true;
    $event->return = $page->name . '.html';
  }
});

 

Snagged from here originally:

 

 

  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...