Posts in collection being redirected to their non collection URL

#1

I’m setting up a collection with my routes looking like this:

routes:

collections:
  /:
    permalink: /{slug}/
    template: index
  /photos/:
    permalink: /photos/{slug}/
    template: photos
    filter: primary_tag:photos
    data: tag.photos

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

If I create a post with the photos tag I can get it to show up with the correct url on my photos landing page with the url http://localhost:2368/photos/bvi but clicking on goes through two redirects:

Request URL: http://localhost:2368/photos/bvi
Request Method: GET
Status Code: 301 Moved Permanently
Remote Address: [::1]:2368
Referrer Policy: no-referrer-when-downgrade
Cache-Control: public, max-age=31536000
Connection: keep-alive
Date: Fri, 15 Mar 2019 23:41:22 GMT
Location: /photos/bvi/
Transfer-Encoding: chunked
X-Powered-By: Express
Request URL: http://localhost:2368/photos/bvi/
Request Method: GET
Status Code: 301 Moved Permanently
Remote Address: [::1]:2368
Referrer Policy: no-referrer-when-downgrade
Cache-Control: public, max-age=31536000
Connection: keep-alive
Content-Length: 66
Content-Type: text/html; charset=utf-8
Date: Fri, 15 Mar 2019 23:41:22 GMT
Location: /bvi/
Vary: Accept, Accept-Encoding
X-Powered-By: Express

The post then works at http://localhost:2368/bvi/

This is running ghost:2.16.4-alpine through docker.

How can I stop the redirect and get the post to stay at http://localhost:2368/photos/bvi/ ?

#2

Ghost uses trailing slashes by default. There is no option to disable this behaviour currently.

#3

That’s not the issue, it’s getting the post to stay at /photos/bvi/ and not just /bvi/

#4

@dls the collections list is in priority order, right now you have your “catch-all” / collection first in the list with no filters so every post will appear in that collection. You want to re-order and ensure filters correctly cancel each other like so:

collections:
  /photos/:
    permalink: /photos/{slug}/
    template: photos
    filter: primary_tag:photos
    data: tag.photos
  /:
    permalink: /{slug}/
    template: index
    filter: primary_tag:-photos
#5

That was it! Thanks

closed #6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.