将 www.sample.com/index.html 重定向到 www.sample.com 以避免重复
如果我将“/index.html”重定向到“/”,这是否允许浏览我的网站,因为它不再有标题为“/index.html”的页面,或者它重定向到的页面(www.sample.com/ )仍然作为索引(默认)页面,从而防止目录被暴露?如果您有索引页面,Web 服务器将不允许您浏览目录,但重定向是否仍保留索引页面,但只是不在 URL 中显示它?
我想在做出改变之前知道,而不仅仅是尝试。我的服务器上只有一个域,并且将按照其他人的建议在我的 .htaccess 文件中使用以下脚本之一:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.sample.com/$1 [R=301,L]
或
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.sample.com/$1 [R=301,L]
任何想法或评论表示赞赏。
If I redirect “/index.html” to “/”, will this allow browsing of my website because it no longer has a page titled “/index.html” or does the page it is redirected to (www.sample.com/) still serve as the index (default) page, thus preventing the directories from being exposed? The web server won't let you browse through directories if you have an index page, but does the redirection still maintain the index page, but just not show it in the URL?
I want to know before I make this change rather than just experimenting. I just have one domain on the server and was going to use one of the following scripts in my .htaccess file as suggested by others:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.sample.com/$1 [R=301,L]
or
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.sample.com/$1 [R=301,L]
Any ideas or comments are appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将index.html更改为index.php,然后将其重定向到www.sample.com
try to change the index.html to index.php, and just redirect it to www.sample.com
apache中的选项
Indexes
负责浏览网站上的文件和目录。将
Options -Indexes
写入.htaccess,它将禁止此类暴露。Option
Indexes
in apache is responsible for browsing files and directories on the website.Write
Options -Indexes
to .htaccess and it will forbid such exposing.