我试图通过显示特定页面来防止浏览子目录中的文件,同时防止两个 URL 上的重复内容。
我在一个子目录中有几个文件,例如:
www.example.com/subfolderA/pageone.html
www.example.com/subfolderA/pagetwo.html
www.example.com/subfolderA/pagethree.html
等等
我不希望用户访问子目录本身 (www.example.com/subfolderA/
) 并查看所有文件的列表。相反,我希望它们被定向到特定页面(不一定称为“index.html”),比方说 pageone.html
。
我已将以下内容放入该子目录中的 .htaccess 文件中:
DirectoryIndex pageone.html
虽然这会阻止浏览文件并显示我想要的页面,但它会导致搜索引擎中出现重复的页面。
www.example.com/subfolderA/
和 www.example.com/subfolderA/pageone.html
如何确保子目录本身不被搜索引擎索引 - 即始终将浏览器中的 URL 更新为 www.example.com/subfolderA/pageone.html
?
这也是满足我要求的最佳解决方案吗?
感谢任何帮助。
谢谢。
最佳答案
要删除重复页面,您可以在 /subfolderA/.htaccess
中设置此规则:
RewriteEngine On
RewriteBase /subfolderA/
RewriteCond %{THE_REQUEST} (/subfolderA)/?[?\s] [NC]
RewriteRule ^$ %1/pageone.html [L,R=301]
关于apache - .htaccess 防止在浏览器中浏览子目录和更新 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25989300/