Search code examples
phpurl-rewritingseoezpublish

Create rewritable URL in ezpublish


I would change my URL article

www.mynews.fr/news/politic/the-new-gouverner-china

To

www.mynews.fr/news/politic/the-new-gouverner-china-16-06-2013-78965

I would referer my articles in Google Actuality. Thank for your feedback.


Solution

  • URL are generated according to the 'URL alias name pattern' parameter when editing a class.

    This means that if you have a class with a title (string type) and a date (date type) attributes, if you use <title>-<date> in the URL alias name pattern field, the URLs will look like : http://my.domain.com/Titre-article-mardi-23-juillet-2013

    Technically the value used by the system to determinate what to use in the URL is given by the title() function of each datatype. Exemple for the date datatype : https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/classes/datatypes/ezdate/ezdatetype.php#L273 The date will be based on your locale but according to the source code I guess that you won't be able to alter the format used (ex: %Y-%m-%d) properly and without hacking the code.

    That said, there's not solution to add something else than information coming from content attributes, and node_id is a property of the object, not an attribute.

    To solve your issue, I would recommend to create a custom datatype which will not do nothing more but implementing a title() function to return what you want for your URL pattern (in your case, the date in the format you want, plus the node_id).

    Hope this helps.