Forum Moderators: phranque

Message Too Old, No Replies

How do I serve a different robots.txt for https:

Is it possible to serve up a different robots.txt file for https

         

SEOHolicc

5:38 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



I have a site that I'm working on that is accessible from https: which the search engines are indexing.

I've read several places suggesting to serve a different robots.txt file if https: is detected, but I couldn't find any examples.

Does anyone know if this can be done?

g1smd

6:38 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do any of these get you started?

[google.com...]

[google.com...]

Are you sure you want a robots.txt solution, or would you be better off invoking a 301 redirect for some requests?

jdMorgan

6:40 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This depends on how your server is configured.

In many cases, the SSL and non-SSL "sites" are served from different directories on the server. In this case, it's a simple matter of putting two robots.txt files on the server, one in each directory.

However, if the SSL and non-SSL content are both served from the same directory, then you'll need either a dynamically-generated robots.txt file (e.g. generated by a script that tests for SSL/non-SSL requests), or you'll need a secondary robots.txt with a different name such as robotsSSL.txt, and a rewriterule to rewrite robots.txt URL requests to that secondary file if the request is made via SSL.

Jim

SEOHolicc

7:33 pm on Jun 18, 2009 (gmt 0)

10+ Year Member



@g1smd, no I don't want to use the robots.txt solution, but I'm looking into it just in case the client doesn't approve using 301 redirects.

I think I did find some code. I'm not extremely technical so can you tell me if this is what I need?

RewriteEngine on
rewritecond %{SERVER_PORT} ^443$
RewriteRule ^robots\.txt$ robots_ssl.txt [L]

What is this doing? Is the secure server always on port 443? Does this then rewrite robots.txt to robots_ssl.txt if it is on the secure server?

@jdMorgan, no the SSL files are not in a separate directory and are served from the same place.

jdMorgan

10:09 pm on Jun 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is correct except for the casing of "RewriteCond," and you surmise what is does correctly.

It rewrites an incoming HTTP request for the URL-path "/robots.txt" to the local filepath /robots_ssl.txt if that request arrives on port 443, the standard SSL port.

Jim

SEOHolicc

2:33 pm on Jun 19, 2009 (gmt 0)

10+ Year Member



.htaccess sure is some confusing stuff.

Just to be sure, does this mean, in the case of the example above, the ssl robots file is named robots_ssl.txt. Then if the request arrives on the port 443, it will be called up and renamed to robots.txt?

jdMorgan

8:05 pm on Jun 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing is renamed. If the request for the URL robots.txt comes in on port 443, then the content of the file robots_ssl.txt is served. If the request for the URL robots.txt comes in on any other port, then the rule is not invoked, and the content of the file robots.txt is served as it would be normally.

Note the use of the terms "URL" and "file" above. Making this distinction is quite important to avoiding confusion.

Jim

SEOHolicc

2:41 pm on Jun 23, 2009 (gmt 0)

10+ Year Member



Oh I see. Making the distinction between those terms definitely made that understandable. Thanks!

g1smd

2:04 am on Jun 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, it is the key to really 'getting' it.