Live data from Hacker News

Short URLs: Why and How

sive.rs

21–30 of 172 posts

Re: Short URLs: Why and How

#21

Regarding the example of instead of hi.html just name the file hi and use the nginx Config “default_type text/html” —- is there an equivalent to this for other webservers (Eg Caddy etc) ? Perhaps it would be cleaner to just create a directory called hi with and index.html?

I usually create a "file filter" instead. Keep the extension as is (hi.html) and then use the try_files directive in nginx to make the server look for files with the same path using .html as an example. It has been a while since I used nginx but it looks something like this:

try_files $uri.html

Re: Short URLs: Why and How

#22

Regarding the example of instead of hi.html just name the file hi and use the nginx Config “default_type text/html” —- is there an equivalent to this for other webservers (Eg Caddy etc) ? Perhaps it would be cleaner to just create a directory called hi with and index.html?

That Nginx config is so beautiful compared to Apache .htaccess configuration for the same result.

I usually create a "file filter" instead. Keep the extension as is (hi.html) and then use the try_files directive in nginx to make the server look for files with the same path using .html as an example. It has been a while since I used nginx but it looks something like this:

try_files $uri.html

Re: Short URLs: Why and How

#23
How many people type the whole URL and how many access it over Google, QR code, or from other site? This is good if content is unique. I find URLs with dates useful when I want to quickly assess how fresh is the content.

Re: Short URLs: Why and How

#24
post #6

Depending on how much your write, URL collisions can naturally become a real problem. If you use a SSG then all your post HTML documents will be in the same directory, forever. This isn't a problem if you don't spit out posts, but if you post a lot your directory can become rather unwieldy. I'd say, at least throw a year in there: /2022/su/.

Years are a bliss once you want to change your styling and keep an archive as is. Untouched. No work, no risk, nothing breaks.

Cool URIs don't change. Not even their styling.

Re: Short URLs: Why and How

#25
post #6

Depending on how much your write, URL collisions can naturally become a real problem. If you use a SSG then all your post HTML documents will be in the same directory, forever. This isn't a problem if you don't spit out posts, but if you post a lot your directory can become rather unwieldy. I'd say, at least throw a year in there: /2022/su/.

I manage this problem by appending a 5 digit number in front each file, ie. 00001-Hello-world.md that I strip from the URL.

It solves multiple problems for me.

1. All articles are sorted automatically.

2. I can visually see how many drafts I have (drafts are 00000-, published at 00nnn-)

Re: Short URLs: Why and How

#26
post #19

I would have expected something about a super user with the 'su' url. So short urls like this don't make sense if they are not explicit and you don't have a corresponding lookup table

Yeah, I prefer something more meaningful but still succinct like PG's essay urls: http://www.paulgraham.com/articles.html

In OP's case, /short-urls is succinct yet it hints at the content.

Re: Short URLs: Why and How

#27

Regarding the example of instead of hi.html just name the file hi and use the nginx Config “default_type text/html” —- is there an equivalent to this for other webservers (Eg Caddy etc) ? Perhaps it would be cleaner to just create a directory called hi with and index.html?

That Nginx config is so beautiful compared to Apache .htaccess configuration for the same result.

Is it? Assigning text/html to extensionless file would be:

    
        ForceType text/html
    
Which I don't think is that bad, compared to RewriteRule's.

Re: Short URLs: Why and How

#28
post #12

PG's website pretty much does this e.g. from 2003: http://www.paulgraham.com/hundred.html most recent post in 2022: http://www.paulgraham.com/heresy.html I'm not sure I would want to have all my writing in a single directory, but I guess you can't argue with 20 years of longevity ... on both sivers' site and PG's.

You can't determine the file system structure from the URLs. The can map directly, but they don't have to

Also... http?

Re: Short URLs: Why and How

#30

Regarding the example of instead of hi.html just name the file hi and use the nginx Config “default_type text/html” —- is there an equivalent to this for other webservers (Eg Caddy etc) ? Perhaps it would be cleaner to just create a directory called hi with and index.html?

That's that many static site generator do, use a folder and index.html for "clean urls".

Though personally I would do as the other comment said, keep it hi.html and use try_files or mod_rewrite to handle it. I mean, ask me to set up something like this and I probably would never have though of doing it the way in the article. It just seems weird to me.

Post reply on HN