htaccess的子域名与所有的变量文件参数 [英] .htaccess sub domain as file parameter with all the variables

查看:152
本文介绍了htaccess的子域名与所有的变量文件参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用的.htaccess(Linux的/阿帕奇),使这个URL重定向。

I want to make this url redirect using .htaccess (linux/apache) ..

我想保持原样对于这样的WWW子域中的所有通话

I want to keep "as is" all calls for www sub domain like this

www.example.com/index.php
www.example.com/test.php?id=1&name=a
www.example.com/whatever.php?whateverurl=xxxx

但我想重定向所有外卡的网址是这样的子域名作为额外的变量,以目前的无限任何url的变量

but I want to redirect all wild card urls like this with the sub domain as extra variable to current unlimited-whatever url variables

例如

xxx.example.com -> example.com/?subdomain=xxx
yyy.example.com/index.php -> example.com/index.php?subdomain=yyy
whatever.example.com/test.php?var=1 -> example.com/test.php?subdomain=whatever&var=1
whatever.example.com/whatever.php?var1=1&var2=2 -> example.com/whatever.php?subdomain=whatever&var1=1&var2=2

这可能吗?

感谢您

推荐答案

在您设置的通配符DNS记录你应该让你的的.htaccess 文件:

Once you set up your Wildcard DNS Record you should make your .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule ^(.*)\??(.*)?$ $1?host=%{HTTP_HOST}&%{QUERY_STRING} [L] [L]

这个规则的作用,但它会为您提供了一大堆,而不仅仅是子域,你就必须在你的PHP解析。

This rule works, although it will provide you the whole host, rather than just the subdomain, which you'll have to parse in your PHP.

这篇关于htaccess的子域名与所有的变量文件参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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