我想重定向:
情况1. example.com
到subdomain.example.com
情况2. www.example.com
至subdomain.example.com
我已将这2个代码放在httpd.conf中。只有情境2正在运作,而不是情况1.
<VirtualHost *:80>
DocumentRoot "/var/www/html/foo"
ServerName domain.com
ServerAlias subdomain.example.com
<Directory "/var/www/html/foo">
Options Indexes FollowSymLinks Includes
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from All
</Directory>
Redirect permanent http://example.com/ http://subdomain.example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/foo"
ServerName www.example.com
ServerAlias subdomain.example.com
<Directory "/var/www/html/foo">
Options Indexes FollowSymLinks Includes
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from All
</Directory>
Redirect permanent / http://subdomain.example.com/
</VirtualHost>
答案 0 :(得分:1)
我找到了答案。将example.com
和www.example.com
重定向到subdomain.example.com
,然后只设置subdomain.example.com
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com example.com
Redirect permanent / http://subdomain.example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/var/www/html/foo"
ServerName subdomain.example.com
ServerAlias subdomain.example.com
<Directory "/var/www/html/foo">
Options Indexes FollowSymLinks Includes
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
通过在httpd.conf中使用这些代码,我能够:
将example.com
重定向到subdomain.example.com
将www.example.com
重定向到subdomain.example.com
答案 1 :(得分:0)
我想你可以试试这个:
<VirtualHost *:80>
DocumentRoot "/var/www/html/foo"
ServerName www.example.com
ServerAlias example.com
<Directory "/var/www/html/foo">
Options Indexes FollowSymLinks Includes
Options +ExecCGI
AllowOverride All
Order allow,deny
Allow from All
</Directory>
Redirect permanent / http://subdomain.example.com/
</VirtualHost>