重定向所有域别名之一,htaccess的 [英] Redirecting all domain aliases to one with htaccess

查看:127
本文介绍了重定向所有域别名之一,htaccess的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个域别名,而我只想实际使用其中之一。 目前,我已经安装了两个域,

要重定向我想使用htaccess的。

我区目前的工作,像这样:

www.domain.com/index.html - 主域名的主页

www.secondDomain.com/index.html - 显示完全相同的主页作为主域名,但我希望它会自动重命名URL时,它被用来www.domain.com/index.html~~V

谢谢!

解决方案

这是匹配%{HTTP_HOST} 不等于一个简单的问题www.domain.com 和调整,为规范域。

  RewriteEngine叙述上
#如果主机名不www.domain.com
的RewriteCond%{HTTP_HOST}!^ WWW \。域\ .COM $
#301重定向到www.domain.com同一资源
重写规则(。*)http://www.domain.com/$1 [L,R = 301]
 

I have a few domain aliases, while I only want one of them to be actually used. At the moment, I have two domains installed,

To redirect I'd like to use htaccess.

My domains currently work like so:

www.domain.com/index.html - Main domain's home page

www.secondDomain.com/index.html - Displays exactly the same home page as the main domain, but I want it to automatically rename the url to www.domain.com/index.html when it's used.

Thanks!

解决方案

It is a simple matter of matching %{HTTP_HOST} not equal to www.domain.com and redirecting that to the canonical domain.

RewriteEngine On
# If the hostname is NOT www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
# 301 redirect to the same resource on www.domain.com
RewriteRule (.*) http://www.domain.com/$1 [L,R=301]

这篇关于重定向所有域别名之一,htaccess的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆