如何使用PHP和htaccess创建动态子域? [英] How to create dynamic subdomain using PHP and htaccess?
问题描述
我有一个问题:
我想设置PHP和htaccess来创建动态子域。而且我不知道如何。
当前,我的URL如下所示:
I have one problem: I want to set up PHP and htaccess to make dynamic subdomains. And I can not figure out how. Currently my URL looks like this:
www.exemple.com/index.php?subdomain=mike&component=content&id=26&title=people-love-apps
我需要它看起来像这样:
I need it to look like this:
www.mike.exemple.com/content/26/people-love-apps.html
我知道可以做到,但是我不知道如何解决。
对我来说非常重要,使用$ _GET []函数读取URL中的参数。
I know it can be done but I do not know a solution how to do it. Is very important to me with $ _GET [] functions to read parameter in the URL.
问题是我网站上的用户创建了自己的网站,自动获取免费域(子域)。这应该是自动的。
The problem is that users on my site make their web site and get a free domain (sub-domain) automatically. This should be automatic.
谢谢!
推荐答案
您可以t具有 .htaccess
的动态子域
您将需要配置apache虚拟服务器主机以接受多个域的请求
You will need to configure the apache virtual host to accept requests for multiple domains
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com *.example.com
DocumentRoot /www/domain
</VirtualHost>
添加通配符子域 *。example.com
,您的PHP应用程序将收到 example.com
以下任何域(即 garbage.example.com
)下的所有请求, busted.example.com
, llama.example.com
等
Adding the wildcard subdomain *.example.com
, your PHP application will receive all requests for any domain below example.com
, ie garbage.example.com
, busted.example.com
, llama.example.com
, etc.
此时,您的应用程序将必须确定子域的有效性,并显示未知子项的相应错误。
At this point, your application will have to determine the validity of the subdomain and display the appropriate error for unknown subs.
从此处,解析域中的 mike
。
这篇关于如何使用PHP和htaccess创建动态子域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!