Jump to content

urlSegment and page name colliding?


onjegolders
 Share

Recommended Posts

Hi, I've just set up urlSegments on my blog template so that

/blog/category/news

will list all the articles with the category of news

My problem is that if (for some strange reason) a blog article gets called "category" then the subsequent pages will show 404s.

Previously I had it set up so the categories would just show as urlSegment1

ie:

blog/news

but that would also cause a collision if an article gets called "news".

Am sure there's something simple I'm missing here, perhaps I have to add a reserved word somewhere?

Link to comment
Share on other sites

It's not a strange reason. Has I understood, what's happening is that the page url has precedence over the parent page segment. So, when you give the name "category" to a page children of "blog", that's the page that will be accessed from /blog/category/, and if you try to access /blog/category/news/, the system will look for a page called "news" children of "category", or, in case it doesn't exist, the first segment of "children", if activated on it's template.

I'm supposing all this stuff. maybe Ryan can confirm if I'm correct.

Link to comment
Share on other sites

What you can do is forget the segments and create the categories as a pages inside /blog/categories/.

blog

-categories

--news

--..

-posts

--post1

--post2

--..

Like this you would have URLs like /blog/posts/my-first-post and /blog/categories/news

Link to comment
Share on other sites

What you can do is forget the segments and create the categories as a pages inside /blog/categories/.

blog

-categories

--news

--..

-posts

--post1

--post2

--..

Like this you would have URLs like /blog/posts/my-first-post and /blog/categories/news

That's true, I thought about doing that then decided not to but I can't remember why! Wonder what Ryan uses on his profile, I'll check.

Link to comment
Share on other sites

one of the reasons for urlSgment acting as category (tag) might that then it works like a search: it just looks through the articles and if it finds the urlSegment in there, it shows the article.

With pages (and PageField used as tags), both page must exist and article must point to it.

Link to comment
Share on other sites

URL segments are a runtime thing that ProcessWire doesn't know anything about. It only knows where you want to allow URL segments, but not what they are or what you plan to do with them. It's up to you (in your templates) to look for the URL segments you want to act upon. Likewise, it's a best practice to throw Wire404Exception(); when your template gets a URL segment it doesn't recognize. If you want to avoid any possibility of there ever being a collision between a page name and a URL segment, then you wouldn't use URL segments on pages that had children where the URL segment names had potential similarity with the child names. However, I think it's okay to use them in the instance where you are because it seems like there is no chance for a real-world collision here. I would feel comfortable using the URL segment "category" in this instance just because it doesn't seem to be consistent with something that would ever be used as an article title (though that may be just me).

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

×
×
  • Create New...