Jump to content

Recommended Posts

Posted

How to add .html to all links.

For example i have page "news" and i want it to be available at "news.html"

and if i go next level i got "news/my-fist-post.html"

thanks a lot.

Posted

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
Posted
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
Posted
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

Posted

 

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

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
  • Recently Browsing   0 members

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