Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Html .htaccss重写规则_Html_.htaccess_Directory Structure - Fatal编程技术网

Html .htaccss重写规则

Html .htaccss重写规则,html,.htaccess,directory-structure,Html,.htaccess,Directory Structure,我目前的文件夹结构是 root/page1.html root/page2.html root/page3.html root/page3/subpage1.html 我试图使用重写规则来隐藏在浏览器中显示的.html部分 当前.htaccess看起来像: #Alternate default index page DirectoryIndex home.html RewriteCond %{DOCUMENT_ROOT}/$1.html -f RewriteRule ^(.+?)/?$ $1.

我目前的文件夹结构是

root/page1.html

root/page2.html

root/page3.html

root/page3/subpage1.html

我试图使用重写规则来隐藏在浏览器中显示的.html部分

当前.htaccess看起来像:

#Alternate default index page
DirectoryIndex home.html

RewriteCond %{DOCUMENT_ROOT}/$1.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
我遇到的问题是,当我尝试单击一个链接时,它会将我带到root/page3.html,因为它试图重定向到root/page3/.html


解决这个问题的最好办法是什么?我应该为此使用.htaccess还是更改结构?

将规则更改为:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

因此,它现在试图将root/page3/作为它看起来像的目录来访问,而不是html页面本身,我已经编辑了我的原始帖子,以包含完整的.htaccess代码。您在浏览器中看到的URL是什么?错误是什么?使用当前的.htaccess,我知道URL正在读取mywebsite.com/artists/它没有错误,因为它仍然是一个包含多个.html页面的目录,但我希望实现的是,在隐藏URL的.html部分的同时将其设置为mywebsite.com/artists.html。您已经给出了有问题的
page1
page2
等示例,没有提到您的
html
文件名与目录名相同。首先,仅使用站点根目录中存在的有效
.html
文件测试此规则,并查看其是否有效。如果这也不起作用,那么使用完整的htaccess编辑您的问题