gjtorikian / html-proofer

Test your rendered HTML files to make sure they're accurate.
MIT License
1.57k stars 200 forks source link

Warn on permanent redirects (301) #48

Closed doktorbro closed 10 years ago

doktorbro commented 10 years ago

Over the time external links get moved permanently, because nice guys don’t break the web. In most cases that means “the old url is deprecated, use the new url”. Can we have an option to output a warning on those links?

There is another case: automatic server-side redirection, when people forget to add a trailing slash in their internal links. An example is Bootstrap’s main menu: they just list the lazy /components instead of the right /components/. This causes a performance waste.

doktorbro commented 10 years ago

Just found the Typhoeus boolean option followlocation. It’s what I need for external links.

Can we extend the options to internal links?

parkr commented 10 years ago

Make sure this is user-configurable so I can update my links which give 301's and 302's :)

doktorbro commented 10 years ago

@parkr There are no real 301s and 302s for internal links, while we have static files sitting in the filesystem. There is no server here. I assume, that a link to /components means a permanent redirection to /components/ if components is a directory. How would you distinguish a 301 from a 302 without a server?

parkr commented 10 years ago

301 and a 302 are HTTP response codes so without an HTTP connection, they're meaningless. So we'd have to spin up a local server.

parkr commented 10 years ago

Your heuristic of "a link to /components should be changed if components is a directory" makes sense for sure.

doktorbro commented 10 years ago

@parkr I’ve just implemented the feature in #49. What do you think about it?

doktorbro commented 10 years ago

@parkr This feature should work on Jekyll. This commit https://github.com/jekyll/jekyll/commit/d7b5c40901a8657fb5fdf06bbacd7a1059d0aba6 is something you had done after you ran Proofer over the Jekyll docs.

parkr commented 10 years ago

I did that because someone (maybe you?) said you were seeing the Moved Permanently and that they were bad for SEO.

doktorbro commented 10 years ago

@parkr Yes, it was me who proposed the change. With the new feature Proofer would do the same. Sorry for bad description.

doktorbro commented 10 years ago

The description for Apache’s DirectorySlash option contains reasons for internal redirections.

doktorbro commented 10 years ago

Another citation from Yahoo’s Best Practices for Speeding Up Your Web Site:

One of the most wasteful redirects happens frequently and web developers are generally not aware of it. It occurs when a trailing slash (/) is missing from a URL that should otherwise have one. For example, going to http://astrology.yahoo.com/astrology results in a 301 response containing a redirect to http://astrology.yahoo.com/astrology/ (notice the added trailing slash). This is fixed in Apache by using Alias or mod_rewrite, or the DirectorySlash directive if you're using Apache handlers.

doktorbro commented 10 years ago

Done in #49.