Custom output type causes ugly URLs?

Setting a custom output type (PHP in this case) seems to cause Permalinks to go ugly. For example, with this configuration:

[mediaTypes]
[mediaTypes."application/x-php"]
    suffixes = ["php"]

[outputFormats]
[outputFormats.PHP]
    mediaType = "application/x-php"
    rel = "canonical"
    isHTML = true
    permalinkable = true

A file of type PHP and path of content/test/index.md will have a .Permalink of

domain.com/test/index.php

instead of the expected:

domain.com/test/

I tried adding this to the configuration but that didn’t seem to help either:

[permalinks]
    test = '/:section/'

What’s the proper way to generate a pretty url for a custom file type?

tryed noUgly = true ?

@ju52 — I have, unfortunately no improvement in the URL.

Also from the docs:

used to turn off ugly URLs If uglyURLs is set to true in your site. Default: false .

So I think this particular option is to override the main configuration and I don’t have uglyURLs set to true there.

There are two aspects to ugly/pretty URLs.

With the HTML output format in its default configuration…

  1. The path to which the page is rendered

    public/post/test/index.html --> pretty
    public/post/test.html       --> ugly
    
  2. The value of .Permalink and .RelPermalink

    https://example.org/post/test/     --> pretty, relies on server-side config
    https://example.org/post/test.html --> ugly
    

With other output formats …

  1. The path to which the page is rendered

    public/post/test/index.php --> pretty
    public/post/test.php       --> ugly
    
  2. The value of .Permalink and .RelPermalink

    https://example.org/post/test/index.php --> pretty
    https://example.org/post/test.php       --> ugly
    

In both cases…

The path and .Permalink are correct, but in the second case the pretty URL is fully qualified instead of relying on a server-side configuration (e.g., DirectoryIndex in Apache).

If you had a page that produced two output formats, you would need at least one of the URLs to be fully qualified to prevent collisions/ambiguity.

1 Like

Thanks @jmooring! — there is only one output in this case but I take your point. I’ll work around it some other way, either in the templates or with some post-processing.

Yeah, I tried to come up with something for this specific case, but alas, no.

OK, there’s one ugly (sorry) workaround for the case when you have one output format… output both HTML and PHP, but configure your server to look for index.php before index.html.

site configuration

[outputFormats.PHP]
mediaType = "application/x-php"
rel = "canonical"
isHTML = true
permalinkable = false  #  IMPORTANT

front matter

+++
title = 'Test'
date = 2021-01-01T00:00:00-00:00
draft = false
outputs = ['HTML','PHP']
+++
1 Like

That’s awesome, thanks again @jmooring!

In case anyone else plans to use this, the order of outputs in the front matter seems important:

outputs = ['HTML','PHP']

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