I have a site with virtual pages where any request is rewrote to the index page in this way:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
I.e, http://www.example.com/job/edit is rewrote as http://www.example.com/index.php/job/edit where I parse it. That works great.
Now, I need to process every virtual subdomain in order that i.e. http://user1.example.com/job/edit becomes http://www.example.com/index.php/user1/job/edit.
I added in CPanel a wildcard subdomain (*.example.com
), so every subdomain is pointed to the domain folder (without it I got 'Server not found' on every subdomain).
I tried every example that I found here, but I can't get them to work. If I print out $_SERVER['REQUEST_URI']
on the index page, I allways get the last part, but not the subdomain (i.e. /job/edit
).
Is there any way of doing this?
Thanks in advance.
Edit: I already have a workaround for doing it. The $_SERVER['HTTP_HOST']
var contains the whole domain, i.e. user1.example.com
. I can parse it in PHP and extract the subdomain, but I think it should be a more elegant way of doing it.