将多个域重定向到文件夹+非www重定向到www [英] Redirect multiple domains to folder + non-www to www

查看:92
本文介绍了将多个域重定向到文件夹+非www重定向到www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用多个域,并将它们重定向到服务器上的各个文件夹.

So I'm using multiple domains and redirecting them to individual folders on my server.

我正在使用.htaccess进行重定向.我已经设法进行了重定向,但我将非www重定向到www.因此,如果有人在domain.com或domain.co.uk中键入内容,我希望他们重定向到www.domain.com或www.domain.co.uk.请提供一些帮助.这是代码

I'm using .htaccess to do the redirect. I've managed to do the redirects but am to redirect non-www to www. So if somone typed in domain.com or domain.co.uk I'd like them to redirect to www.domain.com or www.domain.co.uk. Would appreciate some assistance please. Here's the code

# pointing for the domain domain.com or domain.co.uk to folder domain
ReWriteCond %{HTTP_HOST} ^domain.com [OR]
ReWriteCond %{HTTP_HOST} ^domain.co.uk [OR]
ReWriteCond %{REQUEST_URI} !domain/
ReWriteRule ^(.*)$ domain/$1 [L]  

推荐答案

# redirect non-www to www
ReWriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301]

ReWriteCond %{HTTP_HOST} ^www.domain.com [OR]
ReWriteCond %{HTTP_HOST} ^www.domain.co.uk [OR]
ReWriteCond %{REQUEST_URI} !domain/
ReWriteRule ^(.*)$ domain/$1 [L]  

这篇关于将多个域重定向到文件夹+非www重定向到www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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