Jump to content

How to use unnatural id's (page ids) in URLs?


saml
 Share

Recommended Posts

This might sound backwards in terms of SEO optimizations, but we have a use case where we would prefer using unnatural ids (such as the page id) for certain page types.

I was wondering how I would most easily implement that? Is there a module for customizing url path behavior, or some simple setting somewhere?

Have googled / browsed around a bit but couldn't find it mentioned anywhere how to go about this.

Link to comment
Share on other sites

There is an option in the module config settings for that - it's called Redirect Type: Redirect vs Load. You'll want the load option. Just an FYI - the modules automatically adds a canonical link to the full url to help search engines.

  • Like 2
Link to comment
Share on other sites

One way without module would be to just enbale urlSegments on home/root template.

Then do create urls with 

domain.com/1003

Then in the template something like this:

if($input->urlSegment1){
   $id = (int) $input->urlSegment1;
   $p = $pages->get("id=$id, include=hidden"); 
   if($p && $p->id && $p->viewable()) {
      echo $p->render();
   } else {
     throw new Wire404Exception();
   }
} else if(count($input->urlSegments) > 1) {
   throw new Wire404Exception();
}
  • Like 3
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...