【问题标题】:htaccess filesmatch(htm|html|php) except two specific files?htaccess filesmatch(htm|html|php) 除了两个特定文件?
【发布时间】:2015-04-22 16:43:52
【问题描述】:

我想为所有 php、htm、html 页面自动添加 X-Robots-Tag 标头,/index.phpforgot.php 除外。

这将涵盖所有这些:

<FilesMatch "\.(htm|html|php)$">
    <IfModule mod_headers.c>
                Header set X-Robots-Tag "noindex, nofollow"
    </IfModule>
</FilesMatch>

但是我怎样才能从 FilesMatch 指令中排除 /index.php/forgot.php

我想要它做什么:

适用于所有 .htm、.html、.php 文件

排除/index.(htm|html|php)/forgot.(htm|html|php),但不是*/index.php应该是有效的。

希望这是有道理的...我只想将其从站点底部的这两个特定文件中排除。

更新:tester 上玩这个,但仍然有一些问题:

(?!.*/(index.php|forgot))(^.*\.(php|htm|html)$)

这不包括像 www.mysite.com/folder/index.php 这样的 URL

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    我一直都在看这个错误。这是我正在使用的:

    # BEGIN noindex,nofollow on all but login and forgot page
    <IfModule mod_env.c>
    RewriteRule ^(index\.php|forgot\.php)$ - [E=exclude:1]
        <FilesMatch "\.(php|html?)$">
            <IfModule mod_headers.c>
                Header set X-Robots-Tag "noindex, nofollow" env=!exclude
            </IfModule>
        </FilesMatch>
    </IfModule>
    

    【讨论】:

      【解决方案2】:

      你试过什么?你有没有尝试过这样的事情?

      &lt;FilesMatch "^(^index|^forgot)\.(htm|html|php)$"&gt;

      只是想为您指明正确的方向。我还没有尝试过,但它可能会有点贪婪,并且匹配像index_example.php 这样的文件。不仅仅是index.php

      这些人对 RegEx 有很好的参考:http://www.regular-expressions.info/

      【讨论】:

      • 这似乎专门匹配 index.phpforgot.php - 而 OP 希望排除这些特定 URL。 (?)
      猜你喜欢
      • 2016-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多