Hacker News new | ask | show | jobs
by BorisTheBrave 2160 days ago
> What are you going to do?

The article addresses this by reminding you that though URIs often look like paths, they can be aribtrarily mapped.

By all means move the resource, but put a redirect under the old URI. This means old links continue to work, which is the key point of the article.

1 comments

Yes. Have you tried to do that even for moderately complex sites?

I have tried to do it a few times, and eventually just gave up. Carrying forward bad naming decisions from the past, is tremendous effort. When cleaning up the house, I also don't leave around sticky notes at the places where I removed documents from.

On top of this:

- When using static site generators, it's not even possible to do 301 redirects (you would have to ugly slow JS version).

- It does not help if you don't own the old DNS name anymore.

> When using static site generators, it's not even possible to do 301 redirects (you would have to ugly slow JS version).

That isn't always true, depending on your choice of web server. You can use mod_rewrite rules in Apache's .htaccess files so if your generator is aware of previous URLs for given content it could generate these to 30x redirect visitors and search bots to the new right place.

Off the top of my head I'm not aware of a tool that does this, but it is certainly possible. It would need to track the old content/layout so you'd need the content in a DB with history tracking (or a source control system) or the tool could leave information about previous generations on each run for later reading. Or it could simply rely on the user defining redirect links for it to include in the generated site.

Of course if you are using a static site generator for maximum efficiency you probably aren't using Apache with .htaccess processing enabled! I suppose a generator could also generate a config fragment for nginx/other similarly though that would not be useful if you are publishing via a web server where you do not have appropriately privileged access to make changes to that.

I have done this for a moderately complex site, it was a bit of work, but not the end of the world. I'm sure some things went missing, but we got 99% of it, which I consider successful enough.

You can do 301s statically, by generating whatever your particular version of an .htaccess file is in place. Or, you can generate the HTML files with the meta-redirect header in place.

The DNS is obviously an issue, but that's not really relevant. The article is advocating for URLs not changing. It's not saying that they mustn't change, just that it's really cool for everyone if they don't.

>When using static site generators, it's not even possible to do 301 redirects (you would have to ugly slow JS version).

I know it's 2020 and all that, but sometimes you don't need 20 MB of minified JS to achieve something: https://en.wikipedia.org/wiki/Meta_refresh

Using a SSG does not mean you don't have a intelligent server that can't do redirects. That's a limitation of certain web hosts (GitHub Pages for eg).

Netlify allows dead simple redirects, and so do most other static hosting platforms.

Even GitHub Pages behind Cloudflare is capable of issuing a 301.
A classic way to do these redirects is on the front web server itself: .htaccess, nginx config, etc.

When you change the structure of your urls, you can generally generate redirect rules to translate old urls to the new structure. Or run a script to individually map each old url to its new one.

Note: I've never done the layter for more than a few hundreds urls, I don't know if it scales well for a very large site

> When cleaning up the house, I also don't leave around sticky notes at the places where I removed documents from.

This is a poor analogy. Perhaps “I’m a librarian for a library with thousands or millions of users, and when I rearrange the books, I don’t leave sticky notes pointing to the new locations”