htaccess 基于主机名或域名重写 [英] htaccess rewrite based on hostname or domain name

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

问题描述

我有两个不同的域(比如 www.site1.com 和 www.site2.com)指向同一个托管服务器.

I have two different domains (let's say www.site1.com and www.site2.com) that point to the same hosting server.

我需要两个不同的域名,因为我想将第一个用于意大利内容,第二个用于英文内容.内容相同,除非语言不同,但域必须不同.

I need the two different domain names because I want to use the first one for the italian contents and the second one for the english contents. The contents are the same, unless for the language, but the domains have to be different.

所以,我想写一个规则,让我翻译:

So, I'd like to write a rule that lets me translate from:

  • www.site1.com/?lang=it

www.site2.com/?lang=en

我通常使用相同的域名为许多不同的语言重写从 www.site.com/it//?lang=it(当然,一个透明的重写 - 用户不会看到任何不同的 URL).

I usually use the same domain name for many different languages rewriting from www.site.com/it/ to /?lang=it (of course, a transparent rewriting - the user doesn't see any different URL).

我想使用不同的域实现相同的目标,但我不知道如何...我已经研究了几个小时,但无法实现我想要的!

I'd like to achieve the same using different domains but I can't figure out how... I've been working on it for hours and I can't achieve what I want!

通常我用这个:

RewriteCond %{REQUEST_URI} /([a-z]{2})
RewriteRule ^([a-z]{2})[/]*$ /index.php?lang=$1 [NC,QSA]

我无法使用不同的域来完成这项工作:

I can't get this one work, to use different domains:

RewriteCond %{HTTP_HOST} ^www.site1\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=it
RewriteRule ^(.*)$ /index.php?lang=it [NC,QSA]

RewriteCond %{HTTP_HOST} ^www.site2\.com [NC]
RewriteCond %{REQUEST_URI} !^/index.php?lang=en
RewriteRule ^(.*)$ /index.php?lang=en [NC,QSA]

推荐答案

Lawrence Cherone - 谢谢你,这个工作就像一个魅力!现在它可以工作了:

Lawrence Cherone - Thank you, that one works like a charm! Now it works:

RewriteCond %{HTTP_HOST} ^www\.site1\.com [NC] 
RewriteRule ^(.*)$ index.php?lang=it [NC,QSA] 
RewriteCond %{HTTP_HOST} ^www\.site2\.com [NC] 
RewriteRule ^(.*)$ index.php?lang=en [NC,QSA] 

当然,我在这条规则之前检查了 www 重定向.

Of course I check the www redirect before this rule.

谢谢!!

这篇关于htaccess 基于主机名或域名重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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