서브도메인 + 서브디렉토리 동시사용 설정방법 도움 부탁드립니다. 채택완료

안녕하세요

서브도메인 + 서브디렉토리 동시사용 설정하려고하는데요

제가하려고하는건

documentRoot/aa 라는 폴더가 있다면

domain.co.kr/aa (O)

aa.domain.co.kr (O)

이렇게 접속이 가능하게 하고싶습니다.

여기서 aa는 동적으로 많이 늘어나는 디렉토리 구조입니다. 

제가한 설정은 아래와 같습니다.

apache/conf/httpd-vhosts.conf

<VirtualHost *:80>
    ServerName domain.co.kr
    ServerAlias *.domain.co.kr
    DocumentRoot "D:\Develop\workspace\php\domain"
    
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^[^.]+.domain.co.kr$
    RewriteRule ^(.+) %{HTTP_HOST}$1 [C] 
    RewriteRule ^([^.]+).future-news.co.kr(.*) D:\Develop\workspace\php\domain/$1/$2
    
    <Directory "D:\Develop\workspace\php\domain">
        Options FollowSymLinks MultiViews
        AddType application/x-httpd-php .php
        AllowOverride FileInfo
        Require all granted
    </Directory>
    
</VirtualHost>

처음 질문올리는데 많은 가르침 부탁드립니다.

답변 3개

채택된 답변
+20 포인트

e.g.

Copy
메인 도메인

    yourdomain.tld (C:/Users/Administrator/Documents/www/yourdomain)

서브 도메인

    a.yourdomain.tld (C:/Users/Administrator/Documents/www/yourdomain/a)

    bb.yourdomain.tld (C:/Users/Administrator/Documents/www/yourdomain/bb)

conf/extra/httpd-vhosts.conf

Copy
<VirtualHost yourdomain.tld:80>
    DocumentRoot "C:/Users/Administrator/Documents/www/yourdomain"

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^([^.]+)\.(yourdomain\.tld)$
    RewriteRule ^ %{REQUEST_SCHEME}://%2/%1%{REQUEST_URI} [QSA,L]
    
    LogFormat "%h %l %u %t %{Host}i \"%r\" %>s %b" common-withdomain
    CustomLog "logs/access.log" common-withdomain
</VirtualHost>

test

Copy
yourdomain.tld

a.yourdomain.tld == yourdomain.tld/a

bb.yourdomain.tld == yourdomain.tld/bb

bb.yourdomain.tld/foo.php?bar=baz == yourdomain.tld/bb/foo.php?bar=baz
로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

아 aa가 고정이아니라 사용자 생성할때 바뀌는거라서요 ㅠㅠ

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

\domain 가 httpd의 root일경우 아래와 같이 셋팅해보시고..
아파치 서버를 재부딩해보시기 바랍니다.

ServerName  aa.domain.co.kr
ServerAlias  www.aa.domain.co.kr

DocumentRoot "D:\Develop\workspace\php\domain\aa"


domain.co.kr/aa (O)
aa.domain.co.kr (O)

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고