如何创建以用户名作为子域名子域?用户名、域名

2023-09-02 00:24:00 作者:安穩

我刚才提到的其他相关问题,但他们并不清楚我的。请给我解释一下:我怎样才能使子域在PHP

I have referred other related question but they are not clear to me. Please explain me: How can I make subdomain in PHP?

例如:

http://www.domainname.com/page.php?usname=sundar

我要改变连结此

I want change the link to this

http://sundar.domainname.com

这是有可能在PHP?还是有其他的方法来做到这一点?

Is this possible in PHP? Or any other way to do it?

推荐答案

您可以创建一个虚拟的子域,然后你可以用htaccess的重定向。

You may create a virtual sub domains and then you can redirect it with .htaccess.

您还可以建立

实录这个样子

* .exmple.com一个127.0.0.1或者你的IP

在您的DNS。

然后添加像这样在您的的.htaccess

Then add something like this in your .htaccess

重写规则^([AA-ZZ])$ home.php?用户名= $ 1

RewriteRule ^([aA-zZ])$ home.php?username=$1

的RewriteCond%{HTTP_HOST} ^(^ )。mywebsite.com   重写规则(的)home.php?用户名=%1

RewriteCond %{HTTP_HOST} ^(^.).mywebsite.com RewriteRule (.) home.php?username=%1

这应该有助于