2012-07-25 3 views
11

내 컴퓨터에 대해 외부 IP 및 호스트 이름을 구성했습니다.IP를 호스트 이름으로 리디렉션하는 Apache httpd.conf

응용 프로그램 내에서 API에 액세스하기 위해 도메인 이름 만 사용하고 있습니다. 따라서 IP 주소를 통해 API에 액세스하려고하면 302 Moved temporary error가 표시됩니다. 그래서 IP 주소로 서버에 도착하는 요청 (Homepage의 경우)은 호스트 이름으로 리디렉션되어야합니다. 사용자가 내가 아파치의 httpd.conf 파일의 리디렉션을 사용하여 시도이를 위해 https://ayz-abc.mysite.com/main

로 리디렉션해야 https://XX.XX.XX.XX/main 칠 때입니다

.

<VirtualHost XX.XX.XX.XX> 

DocumentRoot "/var/www/html" 
#ServerName ayz-abc.mysite.com/ 

# Other directives here 
RewriteEngine On 
RewriteRule /.* https://ayz-abc.mysite.com/ [R] 

</VirtualHost> 

또한 Plsssss 날 도와 다음

<VirtualHost *.portnum> 
DocumentRoot "/var/www/html" 
RewriteEngine On 
RewriteCond %{HTTPS} on 
RewriteRule https://XX.XX.XX.XX/main https://ayz-abc.mysite.com/main [R=301,L] 
</VirtualHost> 

으로 노력했다.

+0

302는 오류가 아닙니다. 서버가 302로 응답하면 리디렉션이 작동합니다. 서버의 HTTP 응답은 무엇입니까? –

+0

UI는 여전히 호스트 이름으로 리디렉션되지 않지만 API는 내부적으로 호스트 이름을 가리 키도록 구성됩니다. 그래서 UI에서 API에 액세스하려고하면 API에 대한 요청 (호스트 이름 포함)은 302 – Poppy

답변

7

좋아, 로그를 다시 볼 수 있습니다. 당신이 호스트 이름이 나를 위해 작동

+1

HTTP_HOST 이외의 나머지 URL을 제거합니다. RewriteRule^(. *) $ https : //ayz-abc.mysite.com$1 [R = 301, L]을 사용하는 것이 더 좋습니다. – pogeybait

1

이 시도 :

RewriteRule $ https://ayz-abc.mysite.com/ [L,R] 

은 또한 당신이 see here

+0

을 표시하지만 사용하려고 시도했지만 여전히 동일한 오류가 발생합니다. 또한 Ankit은 브라우저에서 여전히 IP 주소 만 표시합니다. 호스트 이름이 아닐까요? – Poppy

+0

리디렉션 영구 https : //xx.xx.xx.xx/main https://ayz-abc.mysite.com/main/ 괜찮습니까? – Poppy

1

로도 리디렉션이 조건을 포함하지 않는 경우 당신은 재 작성 조건을

<VirtualHost XX.XX.XX.XX> 

DocumentRoot "/var/www/html" 
#ServerName ayz-abc.mysite.com/ 

# Other directives here 
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^ayz-abc.mysite.com$ 
RewriteRule /.* https://ayz-abc.mysite.com/ [R] 

</VirtualHost> 

가 누락되었습니다. 아파치의 httpd.conf 파일에 구성을 추가

CASE-1 : 사용자가 http://XX.XX.XX.XX/main 또는 http://ayz-abc.mysite.com/main 칠 때 그것은 https://ayz-abc.mysite.com/main로 리디렉션해야

구성 :

# 
# Use name-based virtual hosting. 
# 
NameVirtualHost *:80 
<VirtualHost *:80> 
ServerName XX.XX.XX.XX 
Redirect /main https://ayz-abc.mysite.com/main 
</VirtualHost> 

CASE 2 : 사용자가 https://XX.XX.XX.XX/main 안타 그것을 https://ayz-abc.mysite.com/main

구성 :

로 리디렉션되어야합니다. 0
NameVirtualHost *:443 
<VirtualHost *:443> 
DocumentRoot "/var/www/html" 
#Server Name 
ServerName XX.XX.XX.XX 
SSLEngine on 
SSLOptions +StrictRequire 
# Redirect to the specified URL 
Redirect /main https://ayz-abc.mysite.com/main 
<Directory /> 
SSLRequireSSL 
</Directory> 
.... 
.... 
</VirtualHost> 
0

API를 사용하지 않고 브라우저와 크롤러가 IP 주소 대신 URL로 이동하기를 원한다면 RedirectPermanent를 사용할 수 있습니다.

<VirtualHost XX.XX.XX.XX> 

    RedirectPermanent/http://ayz-abc.mysite.com/ 

</VirtualHost> 

<VirtualHost XX.XX.XX.XX> 

    DocumentRoot "/var/www/html" 
    ServerName ayz-abc.mysite.com/ 

</VirtualHost> 

그것은 검색 엔진에 도움 "향후로 리디렉션되는 URL을 사용하십시오"신호를 301 개 HTTP 상태와 응답의 장점이있다. 사이트를 새 도메인으로 이동하는 경우 동일한 솔루션을 사용해야합니다.

관련 문제