重定向多个域名/网址一,规范域名 [英] Redirecting multiple domains/URLs to one, canonical domain
问题描述
我已经看到了Apache的重写如何指南以非www请求重定向到www请求:
的RewriteCond%{HTTP_HOST} ^!WWW \\ .EXAMPLE \\ .COM [NC]
的RewriteCond%{HTTP_HOST}!^ $
重写规则^ /(。*)http://www.example.com/$1 [L,R]
这对于example.com的所有请求重定向到www.example.com。
但我怎么加入,我想从example1.com,www.example1.com,example2.com,www.example2.com等请求重定向到www.example.com?
编辑:
下面是解决方案:
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^!WWW \\ .EXAMPLE \\ .COM [NC]
的RewriteCond%{HTTP_HOST}!^ $
重写规则^ /?(。*)http://www.example.com/$1 [L,R,NE]
稍有不同的重写规则,并添加RewriteEngine叙述上的
但我怎么加入,我想从example1.com,www.example1.com,example2.com,www.example2.com等请求重定向到www.example.com?
块引用>您已经这样做了。你重写规则规定:如果HTTP_HOST不是www.example.com(而不是空白),重定向到www.example.com。
只要你的服务器设置在你主持www.example.com出的相同目录指向其他领域,你所有的设置。
I've seen the trick on Apache's rewrite guide on how to redirect non-www requests to www requests:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
Which redirects all requests for example.com to www.example.com.
But how do I add in that I want requests from example1.com, www.example1.com, example2.com, www.example2.com, etc. to redirect to www.example.com?
EDIT:
Here's the solution:
RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]
Slightly different RewriteRule and added 'RewriteEngine on'
解决方案But how do I add in that I want requests from example1.com, www.example1.com, example2.com, www.example2.com, etc. to redirect to www.example.com?
You've already done that. Your rewrite rule states "if HTTP_HOST isn't www.example.com (and isn't blank), redirect to www.example.com".
As long as your server is set up to point the other domains at the same directory you're hosting www.example.com out of, you're all set.
这篇关于重定向多个域名/网址一,规范域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!