Forum Moderators: phranque

Message Too Old, No Replies

subdomain rewrite

Need help

         

cdemetriadis

8:56 pm on Mar 4, 2008 (gmt 0)

10+ Year Member



I've been looking all over the web for help, and so far nothing. I guess if I have ANY chances of finding a solution, it'll be in this forum. I've searched most cases, but due to the fact that I'm not proficient in scripting, much less regex, I need your help, step-by-step.

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!

gergoe

12:51 am on Mar 5, 2008 (gmt 0)

10+ Year Member



You will need three things for that, first a modification in your domain records (withing your DNS server) - you'll need to add a wildcard host (*.clients exactly), that should point to your webserver.

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

into the VirtualHost container (which you should have already from the existing configuration).

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]

cdemetriadis

9:11 am on Mar 5, 2008 (gmt 0)

10+ Year Member



Will try that out ASAP

Thanks for the immediate response, I really appreciate it!