.htaccess重写规则不重写别名

我正在尝试为备用子域名提供不同的robots.txt,以便使域名分片,以便Google不索引m1.example.com和m2.example.com。

/etc/httpd/sites-enabled/www.example.com

Alias /robots.txt /var/www/html/robots.txt .... ServerName www.example.com ServerAlias m1.example.com m2.example.com .... DocumentRoot /var/www/www.example.com/public 

/var/www/www.example.com/public/.htaccess

 RewriteEngine on RewriteCond %{HTTP_HOST} !=www.example.com [NC] RewriteRule ^/robots\.txt$ /var/www/html/robots-disallow.txt [L] .... 

当我点击m1.example.com/robots.txt时,它会显示robots.txt而不是robots-disallow.txt。

如果我在/etc/httpd/sites-enabled/www.example.com中将重写规则添加到我的虚拟主机,它可以正常工作,但不会在.htaccess

我通过删除^ / robots.txt $ .htaccess中的正斜杠来解决问题,现在看起来像:

 RewriteRule ^robots\.txt$ /var/www/html/robots-disallow.txt [L] 

在虚拟主机conf它一起工作与.htaccess中的/一旦我删除/它的工作不知道为什么,但这解决了我。