[김성민]님이 남기신 글:
>안녕하세요.
>
>아파치 2.0.63 에서
>
>http://domain.co.kr/board/write.php?table=qna
>
>이것이
>
>http://www.domain.co.kr/board/write.php?table=qna
>
>이렇게 www 가 빠진경우 붙어서 연결시키는 방법을 찾아보고
있습니다.
>웹문서 검색상에서 찾아본 바로는,
>
>
><VirtualHost *>
>RewriteCond %{HTTP_HOST} !^www\.domain\.co\.kr$
>RewriteRule (.*) http://www.domain.co.kr$1 [R=301,L]
></VirtualHost>
>
>이런것과
><VirtualHost *>
>RedirectMatch /(.*)$ http://www.domain.go.kr/$1
></VirtualHost>
>
>이것을 적용해보니 www 붙은거 까지도 접속이 안되더라고요..
>
>
>일부 페이지가 https:// 로 연결되는 곳이 있는데 ssl 연결은
영향받지 않고,
>
>http://domain.co.kr/board/write.php?table=qna
이것이
>http://www.domain.co.kr/board/write.php?table=qna
이런식으로 www 붙어서 리다이렉션 할 수 있는 방법이 있는지
문의드립니다...
========================================
1. 우선 mod_rewrite 모듈이 제대로 작동하는지 확인해 봐야
합니다.
간단하게
RewriteCond %{HTTP_HOST} ^domain\.co\.kr$ [NC]
RewriteRule ^/test/.*$ http://www.domain.co.kr/test.html [R=302,L]
이렇게 설정하면
http://domain.co.kr/test/foobar.php -> http://www.domain.co.kr/test.html
으로 redirect 해야 정상 작동하는 겁니다.
만약 rewrite 모듈이 제대로 작동하지 않는다면 RewriteEngine 이 On
되어 있는지 확인해보시길 바랍니다.
2. VirtualHost 섹션에 www.domain.co.kr 과 domain.co.kr 2개의 도메인과
있다면
간단하게
RewriteCond %{HTTP_HOST} ^domain\.co\.kr$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.kr$1 [L]
이렇게 설정하면 됩니다.
3. 아래 설정은 틀린것 같지 않은데 잘 작동하지 않으면
rewrite.log 를 확인해 보세요.
RewriteEngine On
RewriteLogLevel 3
RewriteLog "/usr/local/apache/logs/rewrite.log"
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.kr$ [NC]
RewriteRule ^(.*)$ http://www.domain.co.kr$1 [L]
참고로 [NC] flag 는 NoCase 입니다.
4. https
https 는 별도의 VirtualHost 섹션에서 설정해서 RewriteRule 이
적용되지 않게 설정하면 됩니다.
아 그리고 naver 스팸페이지로 이동한것은
http://www.linuxchannel.net/?vhost=denyword
에서 text Array [2] 에 매치되어서 그런것 같네요.
(스팸글이 ... 하루에 20~30개씩 올라옵니다)