mod-rewrite子域到PHP中GET变量 [英] Mod Rewrite Subdomain to PHP with GET variable

查看:199
本文介绍了mod-rewrite子域到PHP中GET变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想换行我的头周围mod-rewrite,但似乎无法想出解决办法。

有没有一种方法,我可以做到以下几点?

在用户类型: http://wildcard.mydomain.com

默默写到:

  http://mydomain.com/index.php?username=wildcard
 

解决方案

您必须捕获一个的 的RewriteCond 然后用此在的 重写规则 。附加的RewriteCond 是那里prevent www.mydomain.com 指数.PHP 被改写

  RewriteEngine叙述上
的RewriteCond%{HTTP_HOST}!^ WWW \。
的RewriteCond%{REQUEST_URI}!指数\ .PHP
的RewriteCond%{HTTP_HOST} ^(。+?)\。MYDOMAIN \ .COM $
重写规则。* /index.php?username=%1 [L]
 

但是,这是所需要的功能的一小部分。此外,您必须对您的所有 username.mydomain.com 域名或设置一个的通配符DNS 作品 *。mydomain.com 指向您的主机。

否则,客户端尝试联系 jcraine.mydomain.com ,例如,而没有找到DNS条目和抱怨。

如果这是一个虚拟主机,还必须添加一个 ServerAlias​​ 为每个用户名

  ServerAlias​​ jcraine.mydomain.com
 

或通配符捕获所有子

  ServerAlias​​ * .mydomain.com
 

I'm trying to wrap my head around mod rewrite, but can't seem to figure this out.

Is there a way I could do the following?

User types in: http://wildcard.mydomain.com

Silently writes to:

http://mydomain.com/index.php?username=wildcard

解决方案

You must capture the first part of the domain in a RewriteCond and then use this in a RewriteRule. The additional RewriteConds are there to prevent www.mydomain.com and index.php being rewritten

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{REQUEST_URI} !index\.php
RewriteCond %{HTTP_HOST} ^(.+?)\.mydomain\.com$
RewriteRule .* /index.php?username=%1 [L]

But this is only a small part of the needed functionality. Additionally, you must setup DNS entries for all of your username.mydomain.com domain names or setup a wildcard DNS entry *.mydomain.com pointing to your host.

Otherwise, the client tries to contact jcraine.mydomain.com, for example, and doesn't find a DNS entry and complains.

If this is a virtual host, you must also add a ServerAlias for each of your usernames

ServerAlias jcraine.mydomain.com

or a wildcard catching all subdomains

ServerAlias *.mydomain.com

这篇关于mod-rewrite子域到PHP中GET变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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