我试图重写基于服务器的域的文件名。
下面的代码是错误的/不工作,但说明了预期的效果。
<If "req('Host') != '*.mydevserver.com'"> RewriteRule "^/robots\.txt$" "robots-staging.txt" [R] </If>
希望的效果是这个htaccess将指向一个不同的robots.txt取决于它是否在分期(通配符子域)或不。
用法示例:
http://client1.devsite.com/robots.txt重写为
http://client1.devsite.com/robots-staging.txt
http://client2.devsite.com/robots.txt改写为
http://client2.devsite.com/robots-staging.txt
https://client.com/robots.txt不重写
https://myclient.com/robots.txt
我find了我自己的答案。 这按需要工作。
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^(.*)?mydevserver(\.com) RewriteRule ^robots\.txt$ robots-staging.txt [NS] </IfModule>