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

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

问题描述

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

我需要两个不同的域名,因为我想用第一个为意大利的内容,第二个为英文内容。内容是相同的,除非该语言,但结构域的有无的是不同的。

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

  • www.site1.com /?LANG =它

  • www.site2.com /?LANG = EN

我一般都是用同一个域名为许多不同的语言,从 www.site.com/it / 重写 /?LANG =它。(当然,一个透明的改写 - 用户不会看到任何不同的URL)

我想使用不同的域来达到同样的,但我不能想出如何......我已经工作了好几个小时,我无法实现我想要的!

通常我用这样的:

 的RewriteCond%{REQUEST_URI} /([AZ] {2})
重写规则^([AZ] {2})[/] * $ /index.php?lang=$1 [NC,QSA]
 

我不能得到这个工作,用不同的领域:

 的RewriteCond%{HTTP_HOST} ^ www.site1 \ .COM [NC]
的RewriteCond%{REQUEST_URI}!^ /的index.php?LANG =它
重写规则^(。*)$ /index.php?lang=it [NC,QSA]

的RewriteCond%{HTTP_HOST} ^ www.site2 \ .COM [NC]
的RewriteCond%{REQUEST_URI}!^ /的index.php?LANG = EN
重写规则^(。*)$ /index.php?lang=en [NC,QSA]
 

解决方案

劳伦斯Cherone - 谢谢你,一个工程就像一个魅力!现在,它的工作原理:

 的RewriteCond%{HTTP_HOST} ^ WWW \ .site1 \ .COM [NC]
重写规则^(。*)$的index.php?LANG =吧[NC,QSA]
的RewriteCond%{HTTP_HOST} ^ WWW \ .site2 \ .COM [NC]
重写规则^(。*)$的index.php?LANG = EN [NC,QSA]
 

我当然这个规则之前检查WWW重定向。

感谢你!

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 to /?lang=it

  • www.site2.com to /?lang=en

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!

Usually I use this:

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

Of course I check the www redirect before this rule.

Thank you!!

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

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