我的根目录中有以下 .htaccess 文件:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
这适用于将我所有的 URL 缩短到 website.com/something
问题是 Google 在我的根目录中找不到我的
robots.txt
文件。上面的文件没有让它通过。当它输入 website.com/robots.txt 时,我得到一个 404 未找到。但是如果我注释掉上面的 .htaccess
代码,我就可以很好地完成它。如何编辑我的
.htaccess
文件以让 robots.txt
通过而不干扰我的其他 URL?
最佳答案
RewriteEngine on
RewriteRule ^robots.txt - [L]
第二行将从 URL 重写规则中排除 robots.txt。试试上面的代码
关于.htaccess 不让 robots.txt 通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9546032/