我如何重定向到不同的页面取决于主机名.htaccess重写条件/规则


How do I redirect to different page depending on the HOSTNAME .htacces with a Rewrite Condition/Rule

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

不是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]

如果您想将任何对asdf域名的请求重定向到hello.html在asdf上,并将任何对fdsa的请求重定向到好孩子。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]