Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
网站URL不应以.html扩展名打开_Html_.htaccess_Url_Redirect - Fatal编程技术网

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

网站URL不应以.html扩展名打开,html,.htaccess,url,redirect,Html,.htaccess,Url,Redirect,我想在URL中隐藏.html扩展名,这是通过编辑.htaccess文件实现的。如果我单击任何页面,那么它将打开,没有.html扩展名,但是当我手动输入带有.html扩展名的url时,它也会打开页面,并且.html扩展名会显示在url中 RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.html [L] RewriteEng

我想在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
重新编写引擎打开
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$$1.html[L]
重新启动发动机
重写cond%{HTTPS}=在…上
重写规则^/?(*)https://%{SERVER_NAME}/$1[R,L]
#php——开始cPanel生成的处理程序,不编辑
#将“ea-php71”包设置为默认的“PHP”编程语言。
AddHandler应用程序/x-httpd-ea-php71.php.php7.phtml
#php——结束cPanel生成的处理程序,不编辑
我的要求是,即使在url中输入.html,也不允许打开页面。或者,当用户输入扩展名为.html的URL时,它应该自动重定向

我不知道上面的代码是否正确。请帮我修一下。
网站:

我玩了一会儿,得到了以下.htaccess配置:

这将从URL中删除.html,并确保在访问URL时加载.html文件而不使用.html

您可以在此处进行测试:

重新编写引擎打开
RewriteCond%{THE_REQUEST}/([^.]+)\.html[NC]
重写规则^/%1[NC,L,R]
RewriteCond%{REQUEST_FILENAME}.html-f
重写规则^%{REQUEST_URI}.html[NC,L]
重新启动发动机
重写cond%{HTTPS}=在…上
重写规则^/?(*)https://%{SERVER_NAME}/$1[R,L]
#php——开始cPanel生成的处理程序,不编辑
#将“ea-php71”包设置为默认的“PHP”编程语言。
AddHandler应用程序/x-httpd-ea-php71.php.php7.phtml
#php——结束cPanel生成的处理程序,不编辑

我以前这样使用过它,但它不起作用:RewriteCond%{REQUEST_FILENAME}上的RewriteEngine-d RewriteCond%{REQUEST_FILENAME}\.html-f RewriteRule^(.*)$$1.html[NC,L]与我发布的内容不同,如果用户输入扩展名为.html的URL,我还想强制重定向。它应该重定向到不带.html扩展名的URL。应该这样做,在第二个和第三个块(第7行)之间添加不带引号的“redirect 301/index/”行。
RewriteEngine on 
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.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