【发布时间】:2021-08-11 14:05:30
【问题描述】:
在得知我的客户正在使用 SiteGround 之前,我最初使用 React 构建了我的网站,因此我不得不将所有内容都更改为基本的 HTML 格式。我的导航栏使用 href = "fileName.html" 来导航页面。一旦离开主页,这将导致 URL 变为 www."siteName".com/"fileName.html"。
这是我目前在 .htaccess 中从末尾删除 .html 的内容:
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.*) $1.html [L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
这似乎不起作用。我应该更改我的 .htaccess 文件吗?我应该更改导航栏导航页面的方式吗?
【问题讨论】:
-
欢迎来到 SO,感谢分享您的代码。所以你想将 url 从
http://localhost:80/file.html重定向到http://localhost:80/file?我的意思是你在浏览器中点击http://localhost:80/file.html链接吗?请确认一次。
标签: html reactjs .htaccess url nav