question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

making "/index.html" accessible from the browser

See original GitHub issue

… to make “index.html” accessible from browser?

I’m referring to your basic sample project. Everything is working as long as I’m browsing

localhost:3000

But if I call

localhost:3000/index.html

I’m getting

404 - Oh no's! We couldn't find that page :(

That wouldn’t be a big issue for me, but I’m hosting the app using sparkjava with a Jetty server behind. And this guy seems to rewrite any empty path to “index.html” -> 404 -> boom.

Any suggestion?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:16 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
tannerlinsleycommented, Dec 21, 2017

I see what you’re saying. This is what’s happening:

  • The page loads index.html just fine, and you see the simple HTML and CSS that ships on first load.
  • The js is parsed and React mounts. This is when you see the 404. This happens because the route path is seen as /index.html instead of /. In fact, this exact same problem would happen if you were to use create-react-app and react-router. React router will look for a route component with path='/index.html'. When that route is not matched in the component tree, the fallback route is used, which in React Static’s case is the 404 component, naturally.

The only ill-fated way to try and get around this is to somehow register your routes using the suffix, and this simply won’t fly with react-router or the filesystem. It would attempt to create /index.html/index.html.

There are also a slew of other issue that could arise in react-router and react-static because of that change, so I wouldn’t suggest attempting this.

In the end, you will be much better off by implementing a URL rewrite in your server configuration to remove the .html suffix and /index paths from routes that match an HTML file. This may or may not help you: http://www.eclipse.org/jetty/documentation/9.4.x/rewrite-handler.html.

1reaction
pmogollonscommented, May 16, 2019

For anyone stumbling upon this issue, I was able to fix it using JS creating a script tag in the head with the following code

window.location.pathname === '/index.html' && window.history.replaceState('', '', '/');

This method doesnt even redirect and will not show the 404 page because the /index.html path wont be there when react loads.

Maybe something similar can be implemented in the code base of react-static or maybe just documented so that people is aware of this.

In my case it was important because google for some reason was indexing /index.html and all my clients where getting to the 404 page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML: A good basis for accessibility - Learn web development
You should now be well-versed in writing accessible HTML for most occasions. Our WAI-ARIA basics article will help to fill gaps in this ......
Read more >
HTML Accessibility - W3Schools
Always write HTML code with accessibility in mind! Provide the user a good way to navigate and interact ... Make your HTML code...
Read more >
How to make an HTML file accessible to anyone on the internet
To make your website or webpage LIVE you should first select your domain name i.e your website name which will come in the...
Read more >
Chrome Extensions creating a .html page accessible by ...
2. Open a local html page ... Then you can use chrome.tabs.create({ url: chrome.runtime.getURL("index.html") }); to open the local html page.
Read more >
Making Content Accessible | Web Browser Engineering
Browsers therefore offer a range of accessibility features that take advantage of declarative UI and the flexibility of HTML and CSS to make...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found