html网站去掉html后缀
时间: 2023-10-08 08:04:06 浏览: 134
您可以通过使用URL重写或者服务器配置来实现去掉HTML文件后缀的功能。下面是两种常见的方法:
1. 使用URL重写(Apache服务器):
- 确保您的服务器已启用URL重写模块(例如,Apache的mod_rewrite模块)。
- 在网站根目录下创建一个名为`.htaccess`的文件(如果已存在,请编辑该文件)。
- 添加以下代码到`.htaccess`文件中:
```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/?$ $1.html [L]
```
- 保存文件,并将其上传到服务器上。
- 现在,您的网站将会自动去掉HTML后缀。例如,`example.com/about.html`将会显示为`example.com/about`。
2. 服务器配置(Nginx服务器):
- 编辑Nginx配置文件(例如,`/etc/nginx/nginx.conf`)。
- 在`server`块内添加以下代码:
```
location / {
if (!-e $request_filename){
rewrite ^/(.*)$ /$1.html break;
}
}
```
- 保存配置文件,并重新加载Nginx配置。
- 现在,您的网站将会自动去掉HTML后缀。
请确保在进行任何服务器配置更改之前备份相关文件,并在进行更改时小心谨慎。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
function createLink( file, tags ) { const external = Array.isArray( tags ) && tags.includes( 'external' ) ? ' external' : ''; const template =
${ getName( file ) }${ external } ; const link = createElementFromHTML( template ); link.querySelector( 'a[target="viewer"]' ).addEventListener( 'click', function ( event ) { if ( event.button !== 0 || event.ctrlKey || event.altKey || event.metaKey ) return; selectFile( file ); } ); return link; }
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)