开发者

Redirecting all traffic based on Host name

开发者 https://www.devze.com 2023-03-30 07:37 出处:网络
An external server (I\'ll call it \"sub.origin.edu\") redirects all traffic to my webpage. I want to take all traffic from this host, and redirect it to a different site (which I\'ll call \"http://foo

An external server (I'll call it "sub.origin.edu") redirects all traffic to my webpage. I want to take all traffic from this host, and redirect it to a different site (which I'll call "http://foo.target.edu/board/").

My .htaccess file is:

 R开发者_如何转开发ewriteEngine On
 RewriteCond     ${HTTP_HOST}    sub\.origin\.edu [NC]
 RewriteRule     ^(.*)$  http://foo.target.edu/board/ [R=302]

This doesn't seem to be working. I've confirmed (using PHP) that the host is indeed sub.origin.edu, and the .htaccess file is in the right directory, but this rule just doesn't come into effect. Any suggestions? Thanks.

(If I remove the RewriteCond, the redirect happens, so I can confirm that everything but the rewrite condition is working.)


Use this:

RewriteEngine On
RewriteCond     %{HTTP_HOST}   sub\.origin\.edu [NC]
RewriteRule     ^(.*)$  http://foo.target.edu/board$1 [R=302]

You used the wrong substition character ($ instead of %)


I found this question while trying to complete a re-derict for specific hostnames. This link was of great help to understand how RewriteCond and RewriteRule work.

http://httpd.apache.org/docs/2.4/rewrite/intro.html


If sub.origin.edu is doing a 3xx redirect, then the browser will issue a new request to your server using your.server.edu as the host name. So this rule will never match that. If this is the case, there's no easy way to tell where the request was redirected from.

If they're using a CNAME, Femi has the correct answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号