Apache的mod_rewrite规则作为子 [英] Apache mod_rewrite rule as subdomain

查看:122
本文介绍了Apache的mod_rewrite规则作为子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

怎么可以这样

http://some-url.com/?lang=en

改写这样:

http://en.some-url.com ???

用mod_rewrite?

via mod_rewrite?

推荐答案

您可以定义所有可能的子域languages​​pecific在some-url.com的虚拟主机,CONFIGFILE ServerAlias​​并添加以下重写规则

You could define all possible languagespecific subdomains as ServerAlias in the VirtualHost-configfile of some-url.com and add following rewriterule

RewriteEngine On
RewriteCond %{HTTP_HOST} ^some-url\.com$ [NC]
RewriteCond %{QUERY_STRING} lang=(.*)$
RewriteRule . http://%1.some-domain.com/? [R=301,L] 

在你的服务器端脚本,您可以通过检查称为HTTP_HOST服务器/ CGI变量得到实际的语言(PHP中,这将是 $ _ SERVER ['HTTP_HOST'] 而在ColdFusion的这将是#CGI.HTTP_HOST#

In your serverside script you can get the actual language by checking SERVER/CGI variable called HTTP_HOST (in php this would be $_SERVER['HTTP_HOST'] while in ColdFusion this would be #CGI.HTTP_HOST#)

这篇关于Apache的mod_rewrite规则作为子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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