Jump to content
regesh

Add .html instand trailng slash

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...