如何配置htaccess以显示动态的第二个子域

时间:2011-08-12 07:18:31

标签: .htaccess virtual subdomain

我有这个目标:能够重定向或显示虚拟第二个子域的特定页面,如: virtual.hotels.sample.com

我写了这些htaccess规则

RewriteEngine On
Options +FollowSymlinks -Indexes
RewriteBase /

RewriteCond %{HTTP_HOST} !^hotels.sample\.com$
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?hotels.sample\.com$ [NC]
RewriteRule (.*) http://hotels.sample.com/$1 [R=301,L]

RewriteRule ^cheap-hotels-country/([A-Za-z0-9]+)/([A-Za-z0-9]+)\/?$ index.php?country=$1&custom=$2 [L]
RewriteRule ^cheap-hotels-city/([A-Za-z0-9]+)/([A-Za-z0-9]+)\/?$ index.php?city=$1&custom=$2 [L]
RewriteRule ^cheap-hotels-country/([A-Za-z0-9]+)\/?$ index.php?country=$1 [L]
RewriteRule ^cheap-hotels-city/([A-Za-z0-9]+)\/?$ index.php?city=$1 [L]

RewriteRule ^find-cheap-hotels-country/([A-Za-z0-9]+)/([A-Za-z0-9]+)\/?$ index2.php?country=$1&custom=$2 [L]
RewriteRule ^find-cheap-hotels-city/([A-Za-z0-9]+)/([A-Za-z0-9]+)\/?$ index2.php?city=$1&custom=$2 [L]
RewriteRule ^find-cheap-hotels-country/([A-Za-z0-9]+)\/?$ index2.php?country=$1 [L]
RewriteRule ^find-cheap-hotels-city/([A-Za-z0-9]+)\/?$ index2.php?city=$1 [L]

RewriteCond %{HTTP_HOST} ^(.*)\.hotels.sample.com$ [NC]
RewriteCond %1 !^(www)\.hotels.sample.$ [NC]
RewriteRule ^([^/]+)/?$ /home/sample/public_html/index.php [L]

但当然不行。希望有人能帮帮我!!

1 个答案:

答案 0 :(得分:0)

RewriteCond %{HTTP_HOST} !^hotels.asia\.com$
RewriteCond %{HTTP_HOST} ^(.*?)\.(www\.)?hotels.sample\.com$ [NC]
RewriteRule (.*) http://hotels.sample.com/$1 [R=301,L]

请更正!!!假设你的主机是:virtual.hotels.sample.com,所以它会重定向到http://hotels.sample.com/然后这部分永远不会执行:

RewriteCond %{HTTP_HOST} ^(.*)\.hotels.sample.com$ [NC]
RewriteCond %1 !^(www)\.hotels.sample.$ [NC]
RewriteRule ^([^/]+)/?$ /home/sample/public_html/index.php [L]