Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of index.html in URL #1306

Closed
sapegin opened this issue May 31, 2015 · 18 comments · Fixed by #3691
Closed

Get rid of index.html in URL #1306

sapegin opened this issue May 31, 2015 · 18 comments · Fixed by #3691

Comments

@sapegin
Copy link

sapegin commented May 31, 2015

Is there any way to remove index.html from all links?

@thinkingofmaud
Copy link

I noticed this also. I edited the theme. That's how I 'sanitized' the path.

- var regex = /(\/index\.html?$)|(\/?$)/;
- var path = article.path.replace(regex, '');
//-fix for permalink in pages
a(href=url_for(path))
  +title(article)

@tommy351
Copy link
Member

tommy351 commented Jun 5, 2015

This feature is good to have.

@sapegin
Copy link
Author

sapegin commented Jun 5, 2015

I ended up with a helper:

hexo.extend.helper.register('page_url', function(path, options) {
    return this.url_for(path, options).replace(/index\.html$/, '');
});

But internal settings would be better.

@tommy351 tommy351 mentioned this issue Jun 11, 2015
8 tasks
@leesei leesei changed the title Get rid of index.html Get rid of index.html in URL Jul 17, 2015
@leesei leesei added the enhancement New feature or request label Dec 8, 2015
@leesei
Copy link
Member

leesei commented Dec 8, 2015

I'm using this setting and not seeing index.html in the site generated.
How are you guys producing this issue?

permalink: :title/

@sapegin
Copy link
Author

sapegin commented Dec 14, 2015

I gave up with Hexo, so it’s irrelevant for me now.

@sapegin sapegin closed this as completed Dec 14, 2015
@mef
Copy link

mef commented Aug 31, 2016

How are you guys producing this issue?

@leesei this happens on pages, not posts.

See also: #1387 (duplicate?)

@fourpixels
Copy link

Come on guys, what's up with this? I can't believe it's 8 months since last thought (@sapegin quit) and nothing's been fixed?
@sapegin - what are you using now? I just came to hexo because of metalsmith problems, and things continue to go wrong... I'm getting very tired now! :)

@sapegin
Copy link
Author

sapegin commented Sep 1, 2016

@fourpixels I’ve written my own simple generator and now I’m finally happy ;-)

@fourpixels
Copy link

Hey, it looks interesting! Unfortunately I cannot use it right now as I'm in a big hurry and I need out of the box solutions for posts querying, categories, tags and all that crap :(
But it seemed like almost every tool I use has it's own drawbacks. Not only that I need to hack .htaccess file to remove the crappy .index, but I also have to manually copy that file around! (swear)

Good luck with your generator!

@mef
Copy link

mef commented Sep 1, 2016

@fourpixels why not setting a helper, just like @sapegin did?

@fourpixels
Copy link

@mef I already set permalink: :title so it works well. I guess I'm just overwhelmed with all the little things I need to fix just to get it working. I still had to add that .htaccess or my /public/about.html won't be opened from /about/ ;)

@curbengh
Copy link
Contributor

curbengh commented Aug 18, 2019

post.permalink still have "index.html", so plugins that use that variable needs to remove it manually (e.g. #3661 hexojs/hexo-generator-sitemap#59). I wonder if it's safe to remove it directly from the source.

@yoshinorin
Copy link
Member

yoshinorin commented Aug 21, 2019

I wonder if it's safe to remove it directly from the source.

Google crawler seems that sees these as duplicate. I think it would be better if we decide which use in all of hexo source code.

Or add a new option for a user can select by themselves.

If you have a single page accessible by multiple URLs, or different pages with similar content (for example, a page with both a mobile and a desktop version), Google sees these as duplicate versions of the same page. Google will choose one URL as the canonical version and crawl that, and all other URLs will be considered duplicate URLs and crawled less often.

@curbengh
Copy link
Contributor

curbengh commented Aug 22, 2019

I do worry having index.html may negatively affect SEO. Just to clarify, what I meant is removing "index.html" from the source of "permalink" variable,

hexo/lib/models/post.js

Lines 52 to 58 in 651f34b

Post.virtual('permalink').get(function() {
const self = Object.assign({}, ctx.extend.helper.list(), ctx);
const { config } = ctx;
let partial_url = self.url_for(this.path);
if (config.relative_link) partial_url = `/${partial_url}`;
return config.url + partial_url.replace(config.root, '/');
});

by adding following line after line 56:

partial_url = partial_url.replace(/index\.html$/, '');

I concur on having an option. something like,

if (config.canonical_url) {
   partial_url = partial_url.replace(/index\.html$/, '');
}

@curbengh curbengh reopened this Aug 22, 2019
@mef
Copy link

mef commented Aug 22, 2019

what I meant is removing "index.html" from the source of "permalink" variable

How about pages using another file name, like about.html, for which the canonical url should be /about/?

@curbengh
Copy link
Contributor

curbengh commented Aug 22, 2019

you mean when you set

permalink: :year/:month/:day/:title.html

just like theme-next/hexo-theme-next#866?

The main concern of this PR is that permalink could be (I haven't try) "http://example.com/2018/08/20/test-title.html/index.html", the index.html shouldn't be there.

If that config is set, then permalink should be "http://example.com/2018/08/20/test-title.html", as configured.

As for <link rel="canonical" href="http://example.com/2018/08/20/test-title/">, AFAIK the tag is not added by hexo. User can utilize helper function to insert the canonical tag.

hexo.extend.helper.register('canonical_tag', () => {
  return '<link rel="canonical" href="' + post.permalink.replace(/\.html$/, '/') + '">';
});

Note the above codes needs to be refactored into this format to access post.permalink variable.

@mef
Copy link

mef commented Aug 23, 2019

The main concern of this PR is that permalink could be (I haven't try) "http://example.com/2018/08/20/test-title.html/index.html", the index.html shouldn't be there.

Indeed, I was confused about the problem, you may disregard previous comment, thanks.

@curbengh
Copy link
Contributor

const url = options.url || this.url;

this.url also has "index.html".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants