使用.htaccess将目录索引脚本删除(重定向)到目录

时间:2017-05-11 21:15:40

标签: .htaccess

我设法通过web.config在Windows服务器上执行此操作,但不确定.htaccess等效项是什么。基本上只是删除index.html IF ... URL恰好是根目录或任何子目录。

foo.com/index.html >>会变成>>的 foo.com /

foo.com/subdir/index.html >>会变成>>的 foo.com/subdir /

更新:我在这里使用的.htaccess文件确实有效。

DirectoryIndex index.php

<Files .htaccess>
deny from all
</Files>

Options All -Indexes

ServerSignature Off

Options +FollowSymLinks
RewriteEngine On

RewriteBase /

redirectMatch 301 /donation/? /donate/
redirectMatch 301 /giftcard(.*) /gift-card/

RewriteRule ^specials/([0-9]+)/ /specials/index.php\?id=$1 [NC,L]

1 个答案:

答案 0 :(得分:0)

您可以在Apache配置或网站根.htaccess中使用此规则从任何网址中删除/index.html

DirectoryIndex index.html
RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.html [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ %1 [L,R=301,NE]
相关问题