网站URL不应使用.html扩展名打开

问题描述 投票:0回答:1

我想在URL中隐藏.html扩展名,这是通过编辑.htaccess文件来完成的。如果我单击任何页面,则它将打开而没有.html扩展名,但是当我手动输入带有.html扩展名的url时,它也会同时打开该页面,并且.html扩展名会出现在URL中。

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

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

我的要求是即使我在URL中输入.html,也不允许打开页面。或者,当用户输入扩展名为.html的URL时,它应该自动重定向。

我不知道上面的代码是否正确。请帮助我修复它。网站:https://drkrinitamotwani.com/

html .htaccess url redirect web-config
1个回答
0
投票

尝试使用稍微不同的RewriteRule:RewriteRule ^([^\.]+)$ $1.html [NC,L]

所以您的.htaccess现在看起来像这样:

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

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php71” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php71 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
© www.soinside.com 2019 - 2024. All rights reserved.