Forum Moderators: phranque

Message Too Old, No Replies

Syntax for htaccess x-robots tag

         

divinewrite

2:47 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



Hi,

I'm trying to stop SEs from indexing 4 particular flash files on my site, using x-robots in the htaccess file. But I'm new to this, so I'm not sure of my syntax. Is this right?

<IfModule mod_headers.c>
<FilesMatch "Main\.swf">
Header set X-Robots-Tag "noindex"
</FilesMatch>
<FilesMatch "asset\.swf">
Header set X-Robots-Tag "noindex"
</FilesMatch>
<FilesMatch "asset_contents\.swf">
Header set X-Robots-Tag "noindex"
</FilesMatch>
<FilesMatch "loader\.swf">
Header set X-Robots-Tag "noindex"
</FilesMatch>
</IfModule>


I don't want to stop the SEs from indexing ALL flash files, just these 4.

Any help much appreciated.

Cheers.

jdMorgan

3:50 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd code it like this:

<IfModule mod_headers.c>
<FilesMatch "^(Main|asset(_contents)?|loader)\.swf$">
Header set X-Robots-Tag: "noindex"
</FilesMatch>
</IfModule>

The <IfModule> container is only required if you want this code to fail silently on servers where mod_headers isn't available. If you know your server(s) have it available, or if you want an error message if it is not available, then omit the <LoadModule> container.

Jim

[edited by: jdMorgan at 2:17 am (utc) on Feb. 4, 2010]

divinewrite

4:16 pm on Feb 3, 2010 (gmt 0)

10+ Year Member



Thanks Jim. Awesome reply. So the (_contents) makes it work for asset_contents and asset?

jdMorgan

5:51 pm on Feb 3, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No, not exactly -- The (_contents)? makes it work for asset_contents and asset, because the "?" quantifier (meaning "match zero or one occurrence") applies to the preceding parenthesized sub-pattern.

See the Regular Expressions tutorial cited in our Forum Charter if this isn't clear. There's also a very-simplified regex description in the Apache mod_rewrite documentation itself.

Jim

divinewrite

12:05 am on Feb 4, 2010 (gmt 0)

10+ Year Member



Right. Thanks again.

Actually, after removing the <IfModule> container, I get a 500 error on the site. Does this mean they DON'T have mod_headers available?

Cheers.

jdMorgan

1:06 am on Feb 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, that is a likely scenario... ask them.

Jim

divinewrite

1:35 am on Feb 4, 2010 (gmt 0)

10+ Year Member



Thanks Jim. I actually asked them earlier, and they said "This is a standard function in apache and should not be an issue." I've since asked them to double-check for me, and I'm awaiting their response.

jdMorgan

2:19 am on Feb 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just noticed (and corrected) an extra closing parentheses in the code I posted above.

You might want to re-test with that corrected regular-expressions pattern. I suspect that will fix your problem.

Sorry -- sometimes I just type too fast...

Jim

divinewrite

2:44 am on Feb 4, 2010 (gmt 0)

10+ Year Member



BEAUUUUUTIFUL! Thanks so much. That did the trick. You're a champion!