2016-05-14 98 views
2

我目前的.htaccess有重寫規則問題 - 的robots.txt

RewriteRule ^(.+)\.txt$ /404.php [r=301,nc] 

它發生了,所有.txt文件被重定向到404.php

代碼對我來說看起來很不錯,但是這也會重定向robots.txt文件的請求。 我想只取消阻止robots.txt文件,並將其他.txt文件鏈接重定向。

回答

0

您可以使用下列選項之一規則排除的robots.txt文件

  1. 正則表達式negitive lookahed:

    重寫規則((機器人)+?!)。 TXT $ /404.php [R = 301,NC]

  2. negitive的RewriteCond

    的RewriteCond%{REQUEST_URI}!/機器人。 (+)。TXT $ 重寫規則^ TXT $ /404.php [R = 301,NC]

  3. 跳過/robots.txt的

    重寫規則的robots.txt $ - [L] 重寫規則^ (+),TXT $ /404.php [R = 301,NC]

0

使用下面的規則集

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

還是不行這段代碼 – Smaller

+0

你有任何其他規則htaccess文件?無論如何,我已經改變了旗幟。請再試一次。我在localhost測試了它,並且工作正常。 –