Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess filesmatch(htm|html|php) except two specific files?

Tags:

.htaccess

I want to automatically add the X-Robots-Tag header for all php, htm, html pages EXCEPT /index.php and forgot.php.

This would cover all of them:

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

But how can I exclude /index.php and /forgot.php from that FilesMatch directive?

What I want it to do :

Valid for all .htm, .html, .php files

Exclude for /index.(htm|html|php), /forgot.(htm|html|php), but not */index.php should be valid.

Hopefully that makes sense... I just want to exclude it from those two specific files at the base of the site.

UPDATE: Playing around with this on tester, but still have some issues :

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

this is excluding URLs like www.mysite.com/folder/index.php

like image 794
user756659 Avatar asked Sep 17 '26 21:09

user756659


1 Answers

I was looking at this wrong the whole time. Here is what I am using :

# 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>
like image 180
user756659 Avatar answered Sep 21 '26 23:09

user756659



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!