views:

56

answers:

1

Hi all,

I am very new to httpd server. And i have a immediate problem to solve. My server instance is running on centos box.

If a request comes to my server as


http://sub-domain.domain.com


This should be translated to


http://domain.com/key/sub-domain


I have configured many virtual host on my server. But this is quite a case and i am running out of ideas

Any suggestion: what should i do?

+4  A: 

if your using apache

ServerName sub-domain.domain.com
RedirectMatch /(.*) http://domain.com/key/sub-domain/$1

thus

http://sub-domain.domain.com/a-page-i-want-to-see.html

will send a 301 redirect to

http://domain.com/key/sub-domain/a-page-i-want-to-see.html

if you need to dynamically detect the sub-domain, you may need some additional settings.

RewriteCond %{HTTP_HOST} is what you need, but I'm not sure about the specifics of how it works, you may need to use.

I did find the wildcard serverAlais for all the subdomains though.

ServerName domain.com
ServerAlias *.example.com

RewriteCond %{HTTP_HOST} ...
Fire Crow
Hello Fire Crow,actually i don't know well in advance about the value of "sub-domain". It will by system generated key.
vijay.shad
Is there any way, I can test the sub-doamin thing on the localhost?
vijay.shad
I have a local setup that includes bind as a local nameserver, if your on a *nix os you can put the subdomains in your /etc/hosts file
Fire Crow
`RedirectMatch` does send a 302 on default.
Gumbo
Under Windows XP you can find here:c:\WINDOWS\system32\drivers\etc\hosts
Vili
I found some new info on dynamic domains, revised my answer.
Fire Crow
Yes Sir; This dynamic domains are the thing i was looking for and well working poc is achieeved.Thanks for your help Fire Crow.
vijay.shad