如何根据Apache和添加额外的参数域重写URL? [英] How to rewrite URL based on domain in apache and add extra parameter?

查看:211
本文介绍了如何根据Apache和添加额外的参数域重写URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要做的是重写所有的网址,因为我们有很多不同的语言。我们有承载多个域的服务器。我们有www.example.com,www.example.fr,www.example.de,www.anotherdomain.com,www.anotherdomain.de。我想要做的就是从example.xxx所有请求重定向到www.example.com有额外的URL参数郎= EN。这应该不会影响像www.anotherexample.com等其他领域。

Basically, what I want to do is to rewrite all urls because we have many different languages. We have a server that hosts several domains. We have www.example.com, www.example.fr, www.example.de, www.anotherdomain.com, www.anotherdomain.de. What I want to do is to redirect all requests from example.xxx to www.example.com with extra url parameter lang=en. This should not affect other domains like www.anotherexample.com etc.

这不工作:

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.de$
RewriteRule ^(.*)$   http://www.example.com/$1?lang=de [PT]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.fr$
RewriteRule ^(.*)$   http://www.example.com/$1?lang=fr [PT]

一件事,使得它更困难的是,ServerName是比主机名完全不同,它被称为prod.migr.com。

One thing that makes it even more difficult is that the ServerName is totally different than the host name, it is called prod.migr.com.

任何建议将是AP preciated。

Any suggestions would be appreciated.

推荐答案

的PT标志是最有可能您的问题。我从来没有见过当目标是一个完整的域名地址,因为它意味着它使用的URI与mod_alias中得到进一步重定向。

The PT flag is most likely your problem. I've never seen it used when the target is a full domain address because it's meant for URI's to be further redirected with mod_alias.

您应该使用该标志是QSA标志情况下,用户访问的页面上有一个查询字符串。

The flag you should be using is the QSA flag in case the page the user is visiting has a query string on it.

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.de$
RewriteRule ^(.*)$   http://www.example.com/$1?lang=de [QSA]
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.fr$
RewriteRule ^(.*)$   http://www.example.com/$1?lang=fr [QSA]

然而,一个更好的解决办法是检查用户在您的服务器端语言如PHP或ASP访问,如果所有的语言都像这样在同一台服务器上托管的主机。

However, a much better solution would be to check the host the user is visiting in your server-side language such as php or asp if all languages are hosted on the same server like this.

编辑回应其他信息:

您无法通过重写不同的域一样,因为它有重定向请求得到POST变量。

You can not get POST variables through rewriting to different domains like that because it has to redirect the request.

您最好的选择是确定,而不是使用mod_rewrite在你的服务器端语言的语言。

Your best bet is to determine the language in your server side language instead of using mod_rewrite.

如果您使用PHP它会是这样

If you use php it would be like this

$lang = substr(strrchr($_SERVER['HTTP_HOST'], '.'), 1);

其他语言也有类似的方法来确定主机。

Other languages have similar ways to determine the host.

这篇关于如何根据Apache和添加额外的参数域重写URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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