0

I have a multi-user website which generates user profiles.

By default, the profiles as set to the users' id, e.g. mysite.com/userid

I'd like to be able to change that to the username instead, and place it on the subdomain, e.g. username.mysite.com

Both the id and username are unique in mysql so there will be no duplicate issues. But I'm struggling to find a way to do this.

I consulted this article: How to let PHP to create subdomain automatically for each user? Which gave me some idea on how to start, but technically I'm lost.

I added the subdomain *.mysite.com, and tried the following in my .htaccess file:

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^([^a-zA-Z0-9-]*)$  profile/?id=$1
RewriteCond %{HTTP_HOST} ^(^.*)\.mysite.com
RewriteRule (.*)  profile/?id=%1

Where "mysite.com" is my actual site. But it produced 404 errors.

Inside my index.php is the following line for seo profile pages:

$router->map(get_option('profile-seo-url','/profile/:name/:id/:section'), 'profile', array('methods' => 'GET,PUT,POST', 'filters' => array('id' => '(\d+)','section' => '(.*)')));

Is this overriding the htaccess file?

Community
  • 1
  • 1
Quintero
  • 1
  • 1
  • Try: `RewriteCond %{HTTP_HOST} ^((?!www)[^.]+)\.mysite\.com$` – hjpotter92 Oct 19 '15 at 13:46
  • What characters make up the userid? Are you sure the character class in your first `RewriteRule` should be negated ie. `[^a-zA-Z0-9-]` - it doesn't look like it will match much at all? The `CondPattern` is wrong: `^(^.*)\.mysite.com` (you have 2 start of string anchors). You need an `L` flag to stop processing after the first match. If it is `index.php` that is the target then this should be explicitly included in the substitution rather than allowing it to default with `DirectoryIndex`. What is to happen with the path when `username.example.com/path/to/file` is accessed - simply discarded? – MrWhite Oct 19 '15 at 14:45
  • @w3d userid is made up solely of numbers, beginning at 1 (admin). e.g., mysite.com/1 displays my profile because I'm the admin. – Quintero Oct 20 '15 at 18:59

0 Answers0