2013-09-26 4 views
1

.htaccess를 사용하여 특정 디렉토리로 시작하는 경로를 하위 도메인으로 리디렉션하는 데 어려움을 겪고 있습니다. 주요 문제는 내 하위 도메인이 가리키는 디렉토리이므로 실제로 존재할 수 있습니다. 각자 홈 페이지로 리디렉션하여 경로를 유지하는 것에 대해 걱정하지 않습니다. 나는 또한 몇 가지 특정 도메인이 필요가 즉 :htaccess 특정 폴더 하위 도메인으로 리디렉션

website.com/foo -> foo.website.com 
website.com/foo/about.html -> foo.website.com 
website.com/foo/other/index.html -> foo.website.com 

website.com/bar -> foo.website.com 
website.com/foo/about.html -> foo.website.com 
website.com/foo/other/index.html -> foo.website.com 

답변

2

그것은 당신이 Redirect 특정 폴더에 원하는 모양 특정 호스트로 mod_rewrite을 사용하는 대신 mod_aliasRedirectMatch을 사용할 수 있습니다.

RedirectMatch ^/foo[$/]? http://foo.website.com/ 
RedirectMatch ^/bar[$/]? http://foo.website.com/ 

설정에 따라 더 많은 규칙을 추가 할 수 있습니다.

+0

완벽하게 작동하는 것 같습니다. 감사합니다. – kilrizzy

0

httpd.conf 통해 mod_rewrite.htaccess을 활성화하고 다음 DOCUMENT_ROOT/.htaccess 파일에이 코드를 넣어 :

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} !^foo\. [NC] 
RewriteRule ^(foo|bar)(/.*)?$ http://foo.%{HTTP_HOST}/ [L,R=301,NC] 
+0

'website.com/bar-> foo.website.com' 사례에서이 방법을 사용할 수 있습니까? – Qben

+0

일부 편집을했습니다. 귀하의 예에서 일부 복제본이 있었고'website.com/bar -> bar.website.com'을 리디렉션하려고 했으므로 내 솔루션을 제네릭으로 만들었습니다. – anubhava

관련 문제