你如何做通配符子域?

2 .htaccess

我希望 subdomain.example.com 指向 example.com/profile.php?user=subdomain

“子域”随用户输入而变化

你是怎样做的?此外,我希望它是一个静默重定向,因此当用户键入或单击链接时,地址栏中会显示 subdomain.example.com

小智 8

看到这个:http : //www.easymodrewrite.com/example-subdomains 你实际上需要

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
   RewriteRule (.*) domain.com/profile.php?user=%2 [L]
</IfModule>
Run Code Online (Sandbox Code Playgroud)

编辑:要进行“静默”重定向,最后一条规则应该是:

   RewriteRule (.*) /profile.php?user=%2 [L]
Run Code Online (Sandbox Code Playgroud)

确保您profile.phpDocumentRoot设置通配符的目录中有。