0

is possibile to build an url like this without use third party module?

www.mysite.com/template_group/2014/12/12/category_name/url_title

Thanks

1

Yes.

Although seg2cat will make your life easier.

The index template inside your template_group will catch anything (depending on your use of other add-ons such as Structure or Pages and your strict 404 settings).

So in /template_group/index you want to detect the relevant elements of the URL to then deliver your entry. IMO, your URL is a bit pointless - are you really going to have different entries in different categories on the same day to justified such a specific URL?

The only bit that counts is the url_title, which has to be unique through EE anyway, so in your index template, {exp:channel:entries} with the parameters dynamic="no", require_entry="yes" and the all essential url_title="{last_segment}", will display your entry. Everything else in the URL is not used and ignored, which then leads you to the problem of duplicate content.

Using the above approach will generate the same results for all these URLS...

  • www.mysite.com/template_group/2014/12/12/category_name/url_title
  • www.mysite.com/template_group/2014/12/12/url_title
  • www.mysite.com/template_group/2014/12/url_title
  • www.mysite.com/template_group/2014/url_title
  • www.mysite.com/template_group/url_title

So if you must have them in the URL, you'll need to check they're correct and in the correct place.

To validate the date in the landing template use the following:

{if "{segment_2}/{segment_3}/{segment_4}" != "{entry_date format="%Y/%m/%d"}"} {redirect="404"} {/if}

Instead of {last_segment} you could use {segment_6}, but you'll need to get the entry in the template to validate all th other bits - like dates, etc. The category_name is a lot easier and faster if you utilise seg2cat (it's free) and then you can use it in the parameters of the channel:entries call which will make it more secure and unique (less possibility of duplicate URLs and content.

Also see this answer.

EDIT: To complete this answer I've incorporated Filippo's comment to resolve the date validation.

|improve this answer|||||
  • Thanks for your response. Yes, I need a have different entries in different categories on the same day. For me, the main problem is that different URL will generate the same results, as you say. From SEO view I can resolve this with meta canonical, but I want only one valid URL for each entries. You are right on seg2cat to obtain less possibility of duplicate URL. Remains how to validate entry date. Thanks – Filippo Salza Dec 23 '14 at 11:36
  • To validate entry_date: {if {segment_2}/{segment_3}/{segment_4} != {entry_date format="%Y/%m/%d"}} {redirect="404"} {/if} – Filippo Salza Dec 23 '14 at 11:57
  • Have updated answer to include this for completeness. – Peter Lewis Dec 23 '14 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.