RewriteRule问题 - robots.txt

时间:2016-05-14 07:23:49

标签: mod-rewrite

我现在的.htaccess已经

curl -s -u user:pass -X GET "http://your.confluence.com/confluence/rest/api/content?title=testpage&spaceKey=SPACEKEY&expand=body.storage"

碰巧的是,所有RewriteRule ^(.+)\.txt$ /404.php [r=301,nc] 个文件都会重定向到.txt

代码对我来说似乎没问题,但这也会重定向robots.txt文件的请求。 我想仅取消阻止404.php文件并保留其他robots.txt文件链接重定向。

2 个答案:

答案 0 :(得分:0)

您可以使用以下选项之一从规则中排除 robots.txt 文件:

  1. regex negitive lookahed:

    RewriteRule((?!robots)。+)。txt $ /404.php [r = 301,nc]

  2. negitive rewriteCond

    RewriteCond%{REQUEST_URI}!/robots.txt $ RewriteRule ^(。+)。txt $ /404.php [r = 301,nc]

  3. 跳过/robots.txt

    RewriteRule robots.txt $ - [L] RewriteRule ^(。+)。txt $ /404.php [r = 301,nc]

答案 1 :(得分:0)

使用以下规则集

RewriteEngine on
RewriteCond %{REQUEST_URI} !/robots\.txt$
RewriteRule ^(.+)\.txt$ /404.php [R=301,L]
相关问题