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
.htaccess htaccess文件名有问题_.htaccess_Mod Rewrite - Fatal编程技术网

.htaccess htaccess文件名有问题

.htaccess htaccess文件名有问题,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,当我第一次设置我的站点时,我决定将index.html添加到URL中,但现在我遇到了一些问题,当人们删除index.html并尝试访问文件夹时 例如: RewriteRule ^archives/([0-9]+)/([0-9]+)/index.html archive.php?mid=$1-$2 所以当archives/07/2009/将导致错误时,如何避免此错误? 干杯在您的重写规则中选择index.html: RewriteRule ^archives/([0-9]+)/([0-9]+)/

当我第一次设置我的站点时,我决定将
index.html
添加到URL中,但现在我遇到了一些问题,当人们删除
index.html
并尝试访问文件夹时

例如:

RewriteRule ^archives/([0-9]+)/([0-9]+)/index.html archive.php?mid=$1-$2
所以当
archives/07/2009/
将导致错误时,如何避免此错误?
干杯

在您的
重写规则中选择
index.html

RewriteRule ^archives/([0-9]+)/([0-9]+)/(?:index\.html)?$ archive.php?mid=$1-$2

另外,在最初的重写规则中,您忘记了字符串结束锚点
$
。我在上面添加了它。

使用可选的
index.html
尝试此规则:

RewriteRule ^archives/([0-9]+)/([0-9]+)/(index\.html)?$ archive.php?mid=$1-$2
但我建议您只使用这两种符号中的一种,带或不带尾随的
index.html
,如果错误,则重定向:

# remove index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/)?index\.html$ /$1 [L,R=301]

# add index.html
RewriteRule (.*)/$ $1/index.html [L,R=301]

@Gumbo:您可能希望将
index\.html
设为非捕获组。@安德鲁·摩尔:非捕获组仅在Apache 2之后可用。