如何从 URL 中删除 .html Apache/WordPress

[ad_1]

默认情况下, Apache 将 .html 添加到 HTML 文件的 URL。 以下是如何从 URL 中删除 .html Apache. 您可以使用这些步骤从 WordPress、Magento、Drupal、Joomla 和其他 CMS 系统中的 URL 中删除 .html。 您还可以使用它从 URL 中删除 index.html。

从 URL 中删除 .php 扩展名

在继续之前,您需要启用 mod_rewrite Apache 网络服务器。 以下是启用 mod_rewrite (.htaccess) 的步骤 Apache 网络服务器。

1.打开htaccess文件

打开终端并运行以下命令打开 .htaccess 文件。 请根据您的要求将文件路径更改为 .htaccess 文件。

$ sudo vi /var/www/html/.htaccess

奖励阅读:如何从 URL 中删除 .php

2. 从 URL 中删除 .html 扩展名

添加以下行以将所有带有 .html 扩展名的 URL 重定向到不带文件扩展名的 URL。

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html [NC,L] 

在上面的代码中,第一行检查请求是 URL 而不是目录。 第二行将带有 .html 扩展名的匹配 URL 重定向到那些没有文件扩展名的 URL。 最后一行将匹配请求重定向到没有 html 文件扩展名的 URL。

奖励阅读:如何禁用 mod_security Apache

3.重启 Apache 网络服务器

重新开始 Apache 使用以下命令的服务器

$ sudo systemctl restart httpd

CodePre 可以在几分钟内轻松可视化数据,并在实时仪表板中进行监控。 今天就试试吧!

[ad_2]

Related Posts