[SOLVED] URI with and without suffix


(Michael Sauer) #1

Hallo,

how can I archive that Neos allows URIs with and without a suffix? Currently I’ve set the suffix ‘.html’ and when I enter e. g. ‘http://dev.url.de/karriere/stellenangebote/sie-haben-interesse.html’ the page will be displayed. But when I enter ‘http://dev.url.de/karriere/stellenangebote/sie-haben-interesse’ Neos can’t find the page. Is there a way to get this fixed?

We’re using Neos 3.2.0 and the plugin ‘MOC NotFound’.


(Martin Ficzel) #2

Add a second route to the frontend controller with empty suffix. To a Routes.yaml file.

##
# Extra frontend without .html suffix
-
  name:  'Frontend without .html'
  uriPattern: '<FrontendSubRoutes>'
  defaults:
    '@package':    'Neos.Neos'
    '@controller': 'Frontend\Node'
    '@action':     'show'
    '@format':     'html'
  routeParts:
    'node':
      handler:     'Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface'
  subRoutes:
    'FrontendSubRoutes':
      package: 'Neos.Neos'
      suffix:  'Frontend'
      variables:
        'defaultUriSuffix': ''

The created-urls and also canonicals will be created with the first matching route. Make sure that Routes.yaml is included since by default only tho Configuration/*/Routes.yaml will always be included. So if you add this to a package you have to include it in the main Routes.yaml or add a Setting for the inclusion (http://flowframework.readthedocs.io/en/latest/TheDefinitiveGuide/PartIII/Routing.html#subroutes-from-settings)

You can verify the route was included an in the right order with ./flow routing:list command.


(Bastian Waidelich) #3

What he said, but the command is routing:list IIRC :wink:


(Martin Ficzel) #4

thanks … i corrected the typo


(Bastian Waidelich) #5

And, btw, if you want to change the default instead of adding more routes, just override the suffix in the Settings


(Martin Ficzel) #6

Very true, but as i understood he wantend that uris should work with and without ‘.html’


(Michael Sauer) #7

Many thanks, it works! :slight_smile:

But one more question. I’ve added it to the neos/Configuration/Routes.yaml (main Routes.yaml) and now it contains this:

##
# Laudert Website package sub routes
-
  name: 'Laudert Website'
  uriPattern: '<LaudertWebsiteSubRoutes>'
  subRoutes:
    'LaudertWebsiteSubRoutes':
      package: 'Laudert.Website'

##
# Extra frontend without .html suffix
-
  name: 'Laudert Website without .html'
  uriPattern: '<FrontendSubRoutes>'
  defaults:
    '@package':    'Neos.Neos'
    '@controller': 'Frontend\Node'
    '@action':     'show'
    '@format':     'html'
  routeParts:
    'node':
      handler:     'Neos\Neos\Routing\FrontendNodeRoutePartHandlerInterface'
  subRoutes:
    'FrontendSubRoutes':
      package: 'Neos.Neos'
      suffix:  'Frontend'
      variables:
        'defaultUriSuffix': ''

##
# Neos subroutes
# ...

And in my site package there is a Routes.yaml too, where I configure some routes for a Newsletter controller. It contains this:

# Newsletter save recipient
######################################################################
-
  name: 'Laudert.Website Newsletter save route DE with suffix'
  uriPattern: '{node}/speichern.html'
  defaults:
    '@package':    'Neos.Neos'
    '@controller': 'Frontend\Node'
    '@action':     'show'
    '@format':     'html'
    '--laudert_website-newsletter':
      '@package': 'Laudert.Website'
      '@controller': 'Newsletter'
      '@action': 'registerSave'
      '@format': 'html'
  routeParts:
    node:
      handler: Neos\Neos\Routing\FrontendNodeRoutePartHandler
  appendExceedingArguments: TRUE

-
  name: 'Laudert.Website Newsletter save route EN with suffix'
  uriPattern: '{node}/save.html'
  defaults:
    '@package':    'Neos.Neos'
    '@controller': 'Frontend\Node'
    '@action':     'show'
    '@format':     'html'
    '--laudert_website-newsletter':
      '@package': 'Laudert.Website'
      '@controller': 'Newsletter'
      '@action': 'registerSave'
      '@format': 'html'
  routeParts:
    node:
      handler: Neos\Neos\Routing\FrontendNodeRoutePartHandler
  appendExceedingArguments: TRUE

Now that I activated both, suffix and no suffix: do I have to add further configurations for no suffix? And for each language? Is there a possibility to combine the route configuration for all languages and with or without suffix? I hope You understand what I mean :see_no_evil:

Yes I know, but I want that URIs with and without suffix work.


(Bastian Waidelich) #8

May I ask why?
It’s generally not a good idea to have multiple URLs with the same content, even if you use the canonical meta tag.
If you want to make both formats work, I’d rather suggest to create a server-side redirect from *.html to * (or the other way around).

Regarding your question: You can nest sub routes as much as you like. Just define the common defaults in an intermediate sub route


(Michael Sauer) #9

It was a request of my project manager. But I think we have to discuss this problem again, because I agree with You. It should be done on the server side.

Ok thanks, I found something about nested routes in the documentation. I will give it a try :slight_smile:


(Martin Ficzel) #10

It was a request of my project manager.

That is not that uncommon and as long as you have canonical-urls in place, wich make sure only one of the two valid urls is indexed, everything is fine. In general canonical, menus and sitemaps all should point to the preferred format that shall be found by Google.

BTW: With Neos.SEO installed you should be fine.


(Michael Sauer) #11

Yes, Neos.SEO is installed and the canonical URLs are correct. Also on the none .html page is the .html canonical URL. So everything should be fine. :slight_smile:


(Bastian Waidelich) #12

Really?
Ofc, with proper Canonical Tags it shouldn’t be a problem SEO wise, but IMO that’s not the only drawback.
The others (bloated caches, scattered analytics, …) might be negligible but what’s the advantage over a redirect? (just wondering)


(Martin Ficzel) #13

I have three projects i had to configure that way after explicit request by customer/pm.

I see no advantage but i dislike pattern redirects on the webserver: The problem is that those redirects are not handled and known by Neos and often have unexpected side-effects. Configuring an alternate route that creates a redirect via fusion instead of renderinng the document would make sense. That way the redirect would only apply for node-uris and directly show 404 for other paths.


(Bastian Waidelich) #14

Thanks for clarifying, I agree. But I still wonder why customers ask for this… :wink:


(Alexander Berl) #15

The answer to this question is always: “Because they have seen/heard it somewhere.” :wink: