問(wèn)題描述
我正在嘗試圍繞 mod 重寫(xiě),但似乎無(wú)法弄清楚這一點(diǎn).
I'm trying to wrap my head around mod rewrite, but can't seem to figure this out.
有什么辦法可以做到以下幾點(diǎn)嗎?
Is there a way I could do the following?
用戶輸入:http://wildcard.mydomain.com
默默地寫(xiě)信給:
http://mydomain.com/index.php?username=wildcard
推薦答案
您必須在 RewriteCond
然后在 RewriteRule
.額外的 RewriteCond
用于防止 www.mydomain.com
和 index.php
被重寫(xiě)
You must capture the first part of the domain in a RewriteCond
and then use this in a RewriteRule
. The additional RewriteCond
s 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]
但這只是所需功能的一小部分.此外,您必須為所有 username.mydomain.com
域名設(shè)置 DNS 條目或設(shè)置 通配符 DNS 條目 *.mydomain.com
指向您的主機(jī).
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.
否則,例如,客戶端會(huì)嘗試聯(lián)系 jcraine.mydomain.com
,但找不到 DNS 條目并進(jìn)行投訴.
Otherwise, the client tries to contact jcraine.mydomain.com
, for example, and doesn't find a DNS entry and complains.
如果這是虛擬主機(jī),您還必須為每個(gè)添加一個(gè) ServerAlias
你的用戶名
If this is a virtual host, you must also add a ServerAlias
for each of your usernames
ServerAlias jcraine.mydomain.com
或一個(gè)通配符捕獲所有子域
or a wildcard catching all subdomains
ServerAlias *.mydomain.com
這篇關(guān)于Mod使用GET變量將子域重寫(xiě)為PHP的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!