【问题标题】:.htaccess and robots.txt rewrite url how to.htaccess 和 robots.txt 重写 url 如何
【发布时间】:2011-10-28 14:48:58
【问题描述】:

这是我的 .htaccess 代码

RewriteEngine on
RewriteRule (.*) index.html

问题:当访问 mydomain.com/robots.txt 然后页面再次重定向到 index.html
必填:

if(url contain robots.txt) Then   
    redirect to mydomain.com/robots.txt   
else   
    redirect to index.html

【问题讨论】:

    标签: .htaccess url-rewriting robots.txt


    【解决方案1】:

    试试这个:

    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.html
    

    基本上,这两个RewriteCond 告诉 apache 仅当所请求的文件 (-f) 或目录 (-d) 不存在(! 服务作为否定)。

    或者,如果你只需要 robots.txt,你可以使用类似的东西:

    RewriteCond %{REQUEST_URI} !^/robots.txt$
    

    而不是上面的两个RewriteCond

    【讨论】:

    猜你喜欢
    • 2013-04-10
    • 1970-01-01
    • 2018-10-18
    • 2021-01-30
    • 1970-01-01
    • 2014-09-30
    • 2016-11-28
    • 2015-07-28
    相关资源
    最近更新 更多