我有一个网站: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
答案 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]