
가상 호스트에 아직 언급되지 않은 모든 하위 도메인을 ServerName
빈 하위 도메인으로 리디렉션하고 싶습니다. 나는 이 도메인의 다른 모든 가상 호스트 다음에 이것을 내 httpd.conf에 추가하려고 했습니다.
<VirtualHost *:80>
ServerName *.example.com
RedirectPermanent / http://example.com/
</VirtualHost>
이전에 로드된 빈 하위 도메인에 대한 섹션은 다음과 같습니다.
<VirtualHost *:80>
DocumentRoot /var/www/example/htdocs
ServerName example.com
<Directory /var/www/example/htdocs>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
httpd 서비스를 다시 시작한 후 브라우저에서 abc.example.com
. 내가 도대체 뭘 잘못하고있는 겁니까? 설명된 대로 정규식 기반 일치가 필요하지 않기를 바랐습니다.다른 답변에서는이 간단한 작업을 위해.
답변1
메인 블록 아래에 블록을 추가하기만 하면 됩니다.가상 호스트구성 파일. 하위 도메인에 ServerAlias
와일드카드를 사용하여 지정하면 됩니다 . *
마지막으로 를 사용하여 리디렉션 주소를 지정합니다 RedirectPermanent
.
Listen 80
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ServerName example.com
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerAlias *.example.com
RedirectPermanent / http://example.com/
</VirtualHost>
답변2
<VirtualHost *:80>
DocumentRoot "/var/www/example"
ServerName *.example.org
RedirectPermanent / http://example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/example/htdocs"
ServerName example.org
<Directory /var/www/example/htdocs>
Options FollowSymLinks
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
</VirtualHost>
오류 403의 경우 기본 문서를 설정하지 않았기 때문에 폴더 콘텐츠에 액세스하려고 시도했을 수 있습니다. 기본 문서의 경우 예를 들어 사용할 수 있습니다.
DirectoryIndex index.html Index.htm index.php