gma / nesta

File Based CMS and Static Site Generator
http://nestacms.com
MIT License
902 stars 121 forks source link

Redirect paths with trailing slash #60

Closed gma closed 13 years ago

gma commented 13 years ago

If the same page can be served from two URLs that only differ by the presence/lack of a trailing slash, search engines can view the two URLs as separate pages. All pages served by Nesta for URLs that end with a slash should redirect to the URL without the slash.

See this article for background:

http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html

Reported by @nathanaeljones.

lilith commented 13 years ago

Always dropping the slash does simplify things, but it also makes relative paths difficult. I have several index pages with 20+ children, and the absolute paths add quite a bit of text.

What if the the trailing slash is used if the URL path exists as a directory on the filesystem? Would that convention complicate things? Or should it be configurable?

Or am I the only guy wanting a slash? Chime in!

gma commented 13 years ago

The idea of only dropping the slash for some pages hadn't even occurred to me. I appreciate the problem, but don't think that the solution should have an impact on the external interface of a site. The site author should deal with it, and the user shouldn't find themselves wondering why some URLs end in / and others don't.

With your proposal, if you were to create a file called pages/path.mdown the URL would end in /path. If you then decided to add a new page at /path/new-page the URL of /path would change to /path/. I don't like that much; I'd rather go to the trouble to update all my content to use page relative links (e.g. with sed).

To be honest, I don't use relative links at all and always use absolute URLs in my Markdown. It means that my links don't break if I change the URL of a page (which happened quite a bit when I was using relative links). I also use reference style links in my Markdown, so lengthy paths aren't a problem when included in the text.

lilith commented 13 years ago

I've also been thinking about that issue, and I agree - URLs should be all or nothing when it comes to slashes. Personally, I'd much prefer they all have slashes to none having slashes. I don't use fancy relative links, but I use a lot of relative links for direct children, which are less likely to break than absolute paths. Obviously relative links wouldn't work when embedded in another page, but that's kind of a separate issue.

On Mon, Sep 5, 2011 at 1:08 PM, gma < reply@reply.github.com>wrote:

The idea of only dropping the slash for some pages hadn't even occurred to me. I appreciate the problem, but don't think that the solution should have an impact on the external interface of a site. The site author should deal with it, and the user shouldn't find themselves wondering why some URLs end in / and others don't.

With your proposal, if you were to create a file called pages/path.mdown the URL would end in /path. If you then decided to add a new page at /path/new-page the URL of /path would change to /path/. I don't like that much; I'd rather go to the trouble to update all my content to use page relative links (e.g. with sed).

To be honest, I don't use relative links at all and always use absolute URLs in my Markdown. It means that my links don't break if I change the URL of a page (which happened quite a bit when I was using relative links). I also use reference style links in my Markdown, so lengthy paths aren't a problem when included in the text.

Reply to this email directly or view it on GitHub: https://github.com/gma/nesta/issues/60#issuecomment-1998340

gma commented 13 years ago

On 5 Sep 2011, at 12:21, nathanaeljones wrote:

Personally, I'd much prefer they all have slashes to none having slashes.

I think it might be quite an easy to thing to turn on/off in app.rb. I'm hoping to have a look at this ticket later today and see how to do the non-slash version. I'll update this ticket with notes on how to do slashes everywhere if there's a nice way to do it.

lilith commented 13 years ago

Thanks. I'm working on nesta-plugin-aliases. I'm using page.abspath right now as the redirect target, but I'll probably need to change that based on whether slashes are enabled or not.

gma commented 13 years ago

Okay. I'll be stripping all slashes off the URLs when I get to fix the ticket. I've not tried the fix yet, but I'm thinking a Sinatra before filter might be the way to go.

tuupola commented 13 years ago

BTW. You do know that Sinatra now has url helper?

http://www.sinatrarb.com/intro#Generating%20URLs

gma commented 13 years ago

I hadn't seen that. Thanks. I did wonder where to() came from though (I just used it).