用 htaccess 重写域 name/url

Rewrite domain name/url with htaccess

我需要重写以下内容url:

mydomain.com/dashboard/index.php?user=john-dow

john-dow.mydomain.com/dashboard/index.php

所以我想获取查询字符串值并将其放在我的域的开头,后跟一个点。目标是创建自定义用户url,所以看起来对用户很友好。但实际上,我不知道我该怎么做。 .htaccess 可以吗?如果是,如何?

在您的 dashboard/.htaccess 中使用:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^(.+)\.mydomain\.com$ [NC]
RewriteCond %{QUERY_STRING} ^user=(.+)$
RewriteRule ^index\.php$ http://%1.mydomain.com/dashboard/index.php? [R,L]