regesh Posted December 6, 2016 Share Posted December 6, 2016 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. Link to comment Share on other sites More sharing options...
Macrura Posted December 6, 2016 Share Posted December 6, 2016 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 1 Link to comment Share on other sites More sharing options...
regesh Posted December 6, 2016 Author Share Posted December 6, 2016 but is there any option to automate it. such as "add .html to url" ?))) Link to comment Share on other sites More sharing options...
Zeka Posted December 6, 2016 Share Posted December 6, 2016 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. 6 Link to comment Share on other sites More sharing options...
Macrura Posted December 7, 2016 Share Posted December 7, 2016 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 More sharing options...
regesh Posted December 7, 2016 Author Share Posted December 7, 2016 Please help with this. all my SEO jobs failed....... Link to comment Share on other sites More sharing options...
Macrura Posted December 7, 2016 Share Posted December 7, 2016 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: 4 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now