본문 바로가기

WEB/Apache

아파치 Redirect 설정 (예전 주소 등 잘못된 주소를 현재 변경된 주소나 올바른 주소로 자동전환)


출처 : http://free4u.wo.tc/weblog/951

apache웹서버 운영시 이전url로 접근시(현재 존재하지 않는 파일 혹은 링크) REDIRECT를 이용하면 접속자에게 불편함을 주지 않고 새url로 이동시킬수있습니다.


http://free4u.wo.tc/i4u.htm 은 현재 이서버에 존재하지 않지만 http://free4u.wo.tc/ 로 redirect시켜서 이전에
즐겨찾기로 접근한 사람들은 불편없이 사이트를 이용할수있습니다.
뭐 별거 아닌데 글만 길게썼군요^^;

httpd.conf에
Redirect 이전url 새로운url형식으로 넣으면 됩니다.
ex:) Redirect /i4u.htm   http://free4u.wo.tc

아래는 http://apache.org 에 있는 문서내용입니다.

Redirect directive
Syntax: Redirect [status] URL-path URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
Status: Base
Module: mod_alias
Compatibility: The directory and .htaccess context's are only available in versions 1.1 and later. The status argument is only available in Apache 1.2 or later.

The Redirect directive maps an old URL into a new one. The new URL is returned to the client which attempts to fetch it again with the new address. URL-path a (%-decoded) path; any requests for documents beginning with this path will be returned a redirect error to a new (%-encoded) URL beginning with URL.

Example:

Redirect /service http://foo2.bar.com/service
If the client requests http://myserver/service/foo.txt, it will be told to access http://foo2.bar.com/service/foo.txt instead.

Note: Redirect directives take precedence over Alias and ScriptAlias directives, irrespective of their ordering in the configuration file. Also, URL-path must be an absolute path, not a relative path, even when used with .htaccess files or inside of <Directory> sections.

If no status argument is given, the redirect will be "temporary" (HTTP status 302). This indicates to the client that the resource has moved temporarily. The status argument can be used to return other HTTP status codes:

permanent
Returns a permanent redirect status (301) indicating that the resource has moved permanently.
temp
Returns a temporary redirect status (302). This is the default.
seeother
Returns a "See Other" status (303) indicating that the resource has been replaced.
gone
Returns a "Gone" status (410) indicating that the resource has been permanently removed. When this status is used the url argument should be omitted.
Other status codes can be returned by giving the numeric status code as the value of status. If the status is between 300 and 399, the url argument must be present, otherwise it must be omitted. Note that the status must be known to the Apache code (see the function send_error_response in http_protocol.c).

관련 링크: http://httpd.apache.org/docs/mod/mod_alias.html#redirect