Mapping user profile URLs to sub-domains in Wordpress

371 Views Asked by At

Is it possible to map user profile pages to sub-domains in WordPress? I have a membership site and the urls are currently in the form www.example.com/users/SampleUser

However, I want the URL to look like sampleuser.example.com . Is there anyway of achieving this? The users are creating their own profiles by the way on signup and I want it to do this mapping automatically if possible.

1

There are 1 best solutions below

0
On

You'd want to do this through htaccess. The below will map www.example.com/users/sampleuser to sampleuser.example.com/

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# custom rules for subdomain matching
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC]
RewriteRule . http://example.com/users/%1 [R=301,L]

# default WordPress rules
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Hope this helps :)