Forum Moderators: phranque
I have a subdomain setup for all my clients, eg.
[clients.example.com...]
Each client resides in his own folder, eg.
[clients.example.com...]
Every client folder has a few standard sub-folders, one of which is the "under development" site, eg.
[clients.example.com...]
As you can see, the url tends to get very large and not practical for my clients to type in. What I need is a simple redirect, where the url is:
[client-name.clients.example.com...]
Which points to [clients.example.com...]
This also will help keep the url's "cleaner" and easier for the client to remember.
How hard is this?
Please, if possible, do not point me to additional threads, or "similar" situations, unless they provide an exact solution for me.
Thank you all in advance!
Then you need to configure your Apache to respond to request on the same hostname (*.clients.example.com), by adding the
ServerAlias *.clients.example.com
And at last, add some mod_rewrite directives to the same Virtualhost, the following should do it:
#
# Turn on rewriting
RewriteEngine On
#
# Look for the pattern anything.clients.example.com in the Host field of the request.
RewriteCond %{HTTP_HOST} ^(.+)\.clients\.example.com [NC]
#
# Check that the "anything" can be found as a directory with the
# /dev folder in it, otherwise do not rewrite it.
RewriteCond %{DOCUMENT_ROOT}/%1/dev -d
#
# Rewrite the request to the folder of the client, only if both of the
# above conditions has been met.
RewriteRule ^/(.*)$ /%1/dev/$1 [L]