如何根据具有重写条件/规则的HOSTNAME .htaccess重定向到不同的页面

时间:2011-11-22 06:48:14

标签: php apache .htaccess url-rewriting

我有一个网站:www.asdf.com和别名www.fdsa.com

如何检查.htaccess中的HOSTNAME并将其重定向到不同的页面?

我知道这有点像这样:

RewriteRule (%{HTTP_HOST})^(.*)$ http://www.gunslot.com/$2 [L,R=301]

基本上我如何在.htaccess(伪代码)

中做相同的操作
if(hostname == "asdf") redirect to asdf.com/hello.html
if(hostname == "fdsa") redirect to asdf.com/goodbye.html

2 个答案:

答案 0 :(得分:1)

不是100%清楚你想要实现的目标,但这个答案就是你所要求的。

的.htaccess

RewriteCond %{HTTP_HOST} ^asdf\.com
RewriteRule ^(.*)$ http://asdf.com/hello.html [NC,L]

RewriteCond %{HTTP_HOST} ^fdsa\.com
RewriteRule ^(.*)$ http://asdf.com/goodbye.htm [NC,L]

答案 1 :(得分:0)

如果您想将任何请求重定向到asdf上的 asdf hello.html ,以及 fdsa 的任何请求goodbye.html 将以下内容添加到域根目录中的.htaccess文件中。

RewriteEngine On
RewriteBase /
#Redirect any asdf domain or subdomain
RewriteCond %{HTTP_HOST} ^(.+\.)?asdf\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(hello|goodbye)\.html$ [NC]
RewriteRule . http://asdf.com/hello.html [L,R]

#Redirect any fdsa domain or subdomain
RewriteCond %{HTTP_HOST} ^(.+\.)?fdsa\.com$ [NC]
RewriteRule . http://asdf.com/goodbye.htm [L,R]
相关问题