vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.01k stars 2.1k forks source link

Error Rendering the Homepage when i use url like /x/xx #4140

Closed li-jinbao closed 2 months ago

li-jinbao commented 2 months ago

Describe the bug

When I access URLs like /xx, the homepage always appears, which obviously should not happen. However, if I access URLs like /xx.html, the page renders normally. Currently, my project is deployed on Tencent Cloud. The problem does not occur in the development environment, but only after the production deployment, when domain name resolution and Nginx forwarding are involved. Besides,if i click button to some url,it will show correctly . Only when I directly access the URL in the browser, the page rendering error occurs.

Reproduction

git clone https://gitee.com/CrazyClue/vitepress.git use npm install & npm run build nginx:

server {
    listen 443 ssl;
    server_name vite.kuaihe.tech;
    ssl_certificate /etc/letsencrypt/live/kuaihe.tech-0001/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/kuaihe.tech-0001/privkey.pem;

    location / {
        root  /var/www/vitepress;
        index  index.html;
        try_files $uri $uri/ /index.html;
}
}

Expected behavior

My website can show correctly when i access url directly in the browser without “.html” .

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
    CPU: (1) x64 INTEL(R) XEON(R) PLATINUM 8576C
    Memory: 5.50 GB / 7.38 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 20.16.0 - /usr/local/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.8.1 - /usr/local/bin/npm

Additional context

No response

Validations

brc-dd commented 2 months ago

You haven't set cleanUrls: true in your config. https://vitepress.dev/guide/routing#generating-clean-url

li-jinbao commented 2 months ago

The problem has been solved. It was an issue with the Nginx configuration. try_files $uri $uri/ /$uri.html /index.html;