How to serve different robots.txt for http and https on same site?
up vote
10
down vote
favorite
I got a small site which served by Apache (I can't put Nginx in front nor change Apache to anything), and it is set up to serve the same site both over http and https (no redirects http->https is there so far, so both http and https versions are served in parallel).
What I need is to set up .htaccess
so the same URI via http and via https to serve different text file?
Like http://example.com/proto.txt
says "The site is over http" while https://example.com/proto.txt
would say "The site served over https".
apache-2.4 https http htpasswd
add a comment |
up vote
10
down vote
favorite
I got a small site which served by Apache (I can't put Nginx in front nor change Apache to anything), and it is set up to serve the same site both over http and https (no redirects http->https is there so far, so both http and https versions are served in parallel).
What I need is to set up .htaccess
so the same URI via http and via https to serve different text file?
Like http://example.com/proto.txt
says "The site is over http" while https://example.com/proto.txt
would say "The site served over https".
apache-2.4 https http htpasswd
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use aRewriteRule
in your.htaccess
with a condition on it being served over https.
– jcaron
Nov 26 at 12:45
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24
add a comment |
up vote
10
down vote
favorite
up vote
10
down vote
favorite
I got a small site which served by Apache (I can't put Nginx in front nor change Apache to anything), and it is set up to serve the same site both over http and https (no redirects http->https is there so far, so both http and https versions are served in parallel).
What I need is to set up .htaccess
so the same URI via http and via https to serve different text file?
Like http://example.com/proto.txt
says "The site is over http" while https://example.com/proto.txt
would say "The site served over https".
apache-2.4 https http htpasswd
I got a small site which served by Apache (I can't put Nginx in front nor change Apache to anything), and it is set up to serve the same site both over http and https (no redirects http->https is there so far, so both http and https versions are served in parallel).
What I need is to set up .htaccess
so the same URI via http and via https to serve different text file?
Like http://example.com/proto.txt
says "The site is over http" while https://example.com/proto.txt
would say "The site served over https".
apache-2.4 https http htpasswd
apache-2.4 https http htpasswd
edited Nov 26 at 9:37
Mr Shunz
2,23111821
2,23111821
asked Nov 26 at 9:06
Kevin M
515
515
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use aRewriteRule
in your.htaccess
with a condition on it being served over https.
– jcaron
Nov 26 at 12:45
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24
add a comment |
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use aRewriteRule
in your.htaccess
with a condition on it being served over https.
– jcaron
Nov 26 at 12:45
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use a
RewriteRule
in your .htaccess
with a condition on it being served over https.– jcaron
Nov 26 at 12:45
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use a
RewriteRule
in your .htaccess
with a condition on it being served over https.– jcaron
Nov 26 at 12:45
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24
add a comment |
2 Answers
2
active
oldest
votes
up vote
19
down vote
Use an Alias
Create two files, robots.txt and robots_http.txt and add this to your http VirtualHost:
Alias "/robots.txt" "/path/to/documentroot/robots_http.txt"
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
add a comment |
up vote
2
down vote
If you can't or won't change the "main" Apache config but need to do it in a .htaccess
file, you can use a RewriteRule
with a RewriteCond
that checks for HTTPS.
Something along the lines of:
RewriteEngine On
RewriteCond %{HTTPS} "on"
RewriteRule robots.txt robots_https.txt [L]
should probably work (I didn't test it).
Note that this is based on Apache doing HTTPS termination itself. If HTTPS termination is done on a reverse proxy before it, then the condition will likely be different (and will depend on the configuration of the reverse proxy and Apache).
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
19
down vote
Use an Alias
Create two files, robots.txt and robots_http.txt and add this to your http VirtualHost:
Alias "/robots.txt" "/path/to/documentroot/robots_http.txt"
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
add a comment |
up vote
19
down vote
Use an Alias
Create two files, robots.txt and robots_http.txt and add this to your http VirtualHost:
Alias "/robots.txt" "/path/to/documentroot/robots_http.txt"
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
add a comment |
up vote
19
down vote
up vote
19
down vote
Use an Alias
Create two files, robots.txt and robots_http.txt and add this to your http VirtualHost:
Alias "/robots.txt" "/path/to/documentroot/robots_http.txt"
Use an Alias
Create two files, robots.txt and robots_http.txt and add this to your http VirtualHost:
Alias "/robots.txt" "/path/to/documentroot/robots_http.txt"
edited Nov 26 at 9:14
answered Nov 26 at 9:09
Gerald Schneider
5,46212244
5,46212244
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
add a comment |
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
Can not modify vhost settings, can only edit .htaccess, this is the trick.
– Kevin M
Nov 27 at 10:11
add a comment |
up vote
2
down vote
If you can't or won't change the "main" Apache config but need to do it in a .htaccess
file, you can use a RewriteRule
with a RewriteCond
that checks for HTTPS.
Something along the lines of:
RewriteEngine On
RewriteCond %{HTTPS} "on"
RewriteRule robots.txt robots_https.txt [L]
should probably work (I didn't test it).
Note that this is based on Apache doing HTTPS termination itself. If HTTPS termination is done on a reverse proxy before it, then the condition will likely be different (and will depend on the configuration of the reverse proxy and Apache).
add a comment |
up vote
2
down vote
If you can't or won't change the "main" Apache config but need to do it in a .htaccess
file, you can use a RewriteRule
with a RewriteCond
that checks for HTTPS.
Something along the lines of:
RewriteEngine On
RewriteCond %{HTTPS} "on"
RewriteRule robots.txt robots_https.txt [L]
should probably work (I didn't test it).
Note that this is based on Apache doing HTTPS termination itself. If HTTPS termination is done on a reverse proxy before it, then the condition will likely be different (and will depend on the configuration of the reverse proxy and Apache).
add a comment |
up vote
2
down vote
up vote
2
down vote
If you can't or won't change the "main" Apache config but need to do it in a .htaccess
file, you can use a RewriteRule
with a RewriteCond
that checks for HTTPS.
Something along the lines of:
RewriteEngine On
RewriteCond %{HTTPS} "on"
RewriteRule robots.txt robots_https.txt [L]
should probably work (I didn't test it).
Note that this is based on Apache doing HTTPS termination itself. If HTTPS termination is done on a reverse proxy before it, then the condition will likely be different (and will depend on the configuration of the reverse proxy and Apache).
If you can't or won't change the "main" Apache config but need to do it in a .htaccess
file, you can use a RewriteRule
with a RewriteCond
that checks for HTTPS.
Something along the lines of:
RewriteEngine On
RewriteCond %{HTTPS} "on"
RewriteRule robots.txt robots_https.txt [L]
should probably work (I didn't test it).
Note that this is based on Apache doing HTTPS termination itself. If HTTPS termination is done on a reverse proxy before it, then the condition will likely be different (and will depend on the configuration of the reverse proxy and Apache).
answered Nov 27 at 11:10
jcaron
24617
24617
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f941613%2fhow-to-serve-different-robots-txt-for-http-and-https-on-same-site%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Don't quite have the time to check the exact way to write this (and so just a comment, not an answer), but another option if you don't want to or can't change the main Apache config, is to use a
RewriteRule
in your.htaccess
with a condition on it being served over https.– jcaron
Nov 26 at 12:45
@dcaron, this is exactly I need, I just can't figure out how to do that exactly, and need an advice or (better) code snippet to do that :)
– Kevin M
Nov 27 at 10:24