Home > Software engineering >  Intellij idea do not redirect to the root of the project
Intellij idea do not redirect to the root of the project

Time:01-08

Let's say I have a project named project. When I open the index.html using intellij built-in server it shows the url localhost:port/project/index.html However, when I click on a element that has href="/" it shows the url localhost:port/index.html causing css not to be applied and other issues. It works fine if I use href="/project". What could I do?

This project is hosted by github pages and works fine with just "/". So far, to work locally, I made a js script that replace slashes with /project (I know, not elegant and efficient..)

CodePudding user response:

The leading slashes in URL tell the browser to resolve URLs from the web server root. But the built-in web server serves files from http://localhost:63342/<project name>, so no resources can be loaded from http://localhost:63342 - thus the issue. There is unfortunately no way to set it up to use project root as server document root. I can only suggest using URLs relative to current .html file instead of URLs with leading slashes, or use a different web server to host your apps.

Note that we have added some fixes recently that make (most) of absolute paths work on the built-in web server, see https://youtrack.jetbrains.com/issue/WEB-11949/simplify-built-in-web-server-document-root-configuration#focus=Comments-27-5029164.0-0. But some problems still remain, see https://youtrack.jetbrains.com/issue/WEB-57280/Built-in-web-server-URL-links-in-CSS-dont-work-if-CSS-is-loaded-using-absolute-path-with-leading-slash, for example

  • Related