.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之后可用。