Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.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 htaccess url和子文件夹_Html_.htaccess - Fatal编程技术网

Html htaccess url和子文件夹

Html htaccess url和子文件夹,html,.htaccess,Html,.htaccess,我在加载页面时遇到了一些问题,例如,当我用www.domain.com/dogs打开一个页面时,它会显示出来,当我尝试像www.domain.com/dogs/那样打开时,我会得到一个404。子文件夹页面也存在同样的问题 在我的public\uhtml上,我得到了一个index.html和其他4个html页面。在我的子文件夹上,设置相同,但已翻译 我在包含此文件的两个文件夹中都使用了.htacces文件 RewriteEngine On RewriteCond %{REQUEST_FILENAM

我在加载页面时遇到了一些问题,例如,当我用
www.domain.com/dogs
打开一个页面时,它会显示出来,当我尝试像
www.domain.com/dogs/
那样打开时,我会得到一个
404
。子文件夹页面也存在同样的问题

在我的
public\uhtml
上,我得到了一个
index.html
和其他4个html页面。在我的子文件夹上,设置相同,但已翻译

我在包含此文件的两个文件夹中都使用了
.htacces
文件

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

我做错了什么?

您需要在规则中允许
/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)/?$ $1.html [NC,L]
如果您想让相同的规则适用于文件夹(例如dogs/small dogs.html),请使用:


我试着加上这个,但我还是得到了404。还有其他解决方案吗?@josen您的htaccess文件中还有其他规则吗?您也可以尝试清除浏览器缓存。如果dogs.html存在,且原始规则适用于www.domain.com/dogs,则应适用于www.domain.com/dogs/。清除浏览器“否”后,该规则适用于www.domain.com/dogs/。谢谢(使用你的.htaccess)当我尝试exp.www.domain.com/dogs/small dogs/时,我仍然得到404。(子文件夹中的small-dogs.html),当我尝试使用www.domain.com/cats/时也是如此。(公共html文件夹中的cats.html)我需要添加另一条规则?@josen更新后的答案适用于www.domain.com/dogs/small dogs/。不过www.domain.com/cats/应该可以。如果没有,那可能是其他原因造成的。服务器可能找不到该文件。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?:^|/)([^\.]+)/?$ $1.html [NC,L]