如何在.htaccess文件中允许robot.txt

时间:2018-04-10 18:06:37

标签: .htaccess mod-rewrite robots.txt

我正在尝试通过http访问robots.txt和favicon.ico。它们都在我的应用程序的根目录中。我希望他们能够访问mydomain.com/robots.txt和我的robots.txt文件,并使用favicon.ico。我已经查看了互联网上的其他示例和堆栈溢出但我似乎无法使其适用于我的特定.htaccess文件。

RewriteEngine on
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^folder1/(.+)?$ folder1/$1 [L]
RewriteRule ^folder2/(.+)?$ folder2/$1 [L]
RewriteRule ^folder3/(.+)?$ folder3/$1 [L]
RewriteRule ^folder4/(.+)?$ folder4/$1 [L]
RewriteRule ^robots.txt [L]
RewriteRule ^favicon.ico [L]
RewriteBase /
RewriteRule !\.(gif|jpg|jpeg|png|css|js|php|htaccess|xml|htm|html|swf|pdf)$ index.php

<ifModule mod_headers.c>

# Expires after 1 month
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2592000"
</filesMatch>

# Expires after 1 day
<filesMatch ".(jpg|jpeg|gif|png|x-icon)$">
Header set Cache-Control "max-age=31536000"
</filesMatch>
</ifModule>

1 个答案:

答案 0 :(得分:0)

这有效:

RewriteEngine on
RewriteCond %{REQUEST_URI} !=/server-status
RewriteRule ^folder1/(.+)?$ folder1/$1 [L]
RewriteRule ^folder2/(.+)?$ folder2/$1 [L]
RewriteRule ^folder3/(.+)?$ folder3/$1 [L]
RewriteRule ^folder4/(.+)?$ folder4/$1 [L]
RewriteRule "^robots.txt$" "robots.txt" [L]
RewriteRule "^favicon.ico$" "favicon.ico" [L]
RewriteBase /
RewriteRule !\.(gif|jpg|jpeg|png|css|js|php|htaccess|xml|htm|html|swf|pdf)$ index.php

<ifModule mod_headers.c>

# Expires after 1 month
<filesMatch ".(css|js)$">
Header set Cache-Control "max-age=2592000"
</filesMatch>

# Expires after 1 day
<filesMatch ".(jpg|jpeg|gif|png|x-icon)$">
Header set Cache-Control "max-age=31536000"
</filesMatch>
</ifModule>