.htaccess不允许robot.txt通过
我的根目录中有以下.htaccess文件:.htaccess不允许robot.txt通过,.htaccess,robots.txt,.htaccess,Robots.txt,我的根目录中有以下.htaccess文件: Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L] RewriteRule ^([^/]*)$ index.php?page=$1 [NC] 这对缩短我到website.com/something的所有URL都是有效的 问题是谷歌在我的根目录中找不到我的robots.txt文件。上面的文件无法通过。当它输入w
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
这对缩短我到website.com/something的所有URL都是有效的
问题是谷歌在我的根目录中找不到我的robots.txt
文件。上面的文件无法通过。当它输入website.com/robots.txt时,我得到一个404未找到。但是如果我把上面的.htaccess
代码注释掉,我就可以很好地找到它
我如何编辑我的
.htaccess
文件,让robots.txt
通过而不干扰我的其他URL?您可以在.htaccess文件中使用此解决方案:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?page=$1 [L]
这将重写对index.php?page=的所有请求,但RewriteCond
列表中指定的文件除外
RewriteEngine on
RewriteRule ^robots.txt - [L]
第二行将从URL重写规则中排除robots.txt。
试试上面的代码我尝试了两种建议,它们都很有效。但是我用Kiran的答案,只是因为它是一个较短的语法。这就是我的结局
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
# Allow Robots.txt to pass through
RewriteRule ^robots.txt - [L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
查找.htaccess中已存在的行,该行表示:
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
并将其更改为:
RewriteRule ^itemap.xml$ index.php?route=feed/google_sitemap [L]
在我的解决方案中,我解释说,如何不仅排除一个文件,而且排除一个文件和文件夹列表!