Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Cherokee webserver and I wish to redirect all requests to www.domain.com to domain.com without creating a separate virtual server to redirect requests.

In the Host Match section, I've set www.domain.com and domain.com as accepted domains in the wildcard mode. Now I assume that I need to create a rule with the Redirection handler with these settings:

Type: External
Regular Expression: ^/(.*)$
Substitution: http://domain.com/$1

The question is, what type of rule do I select? I've tried the redirection rule with this setting: ^www.domain.com/(.*)$

EDIT: ANSWER

(As ServerFault isn't letting me answer the question yet)

Finally figured it out. Create a rule of the Header type and pick the Host header. Then match this regular expression: ^www.domain.com$. Set the handler to an external redirection with the Regular Expression: ^/(.*)$ and the Substitution: http://domain.com/$1.

Do a Graceful Restart and you should be all set!

share|improve this question
    
I'm not a Cherokee admin, but from the looks of it, the redirection method you are trying to use does not use the Host: header, only the request URI. Unless there's a header matching option for redirections, you probably cannot do your redirect like this. –  DerfK Jul 3 '11 at 21:21
    
@Derf You led me to the correct answer. I'll post it shortly. –  psp Jul 3 '11 at 22:32

2 Answers 2

up vote 1 down vote accepted

Finally figured it out. Create a rule of the Header type and pick the Host header. Then match this regular expression: ^www.domain.com$. Set the handler to an external redirection with the Regular Expression: ^/(.*)$ and the Substitution: http://domain.com/$1.

Do a Graceful Restart and you should be all set!

share|improve this answer

i was looking for something else, but noticed other searchers could use some advice.

UNLESS you want to actually change the address bar in the browser (i.e., from 'www.domain.tld' to 'domain.tld') AND waste bandwidth AND take more time to load, you should just let cherokee continue serving according to the 'match' setup that you can configure for any hosts -- such as 'www' -- that you have not set up in domain name service (DNS) as a CNAME resource record (RR) for your bare domain (domain.tld).

obviously, it far less expensive all round to use DNS to re-direct any hosts to the bare domain [i.e., make a DNS RR: 'host-name IN CNAME domain.tld.' NOTE the "." (dot) after '.tld']. even if you are in a constrained, shared hosting environment using someone else's nameservers, they always make available the capability to setup 'CNAME' RR's for your DNS.

so, this brings us to the question of why one is using any hosts at all. you can eliminate ambiguity by just having all your links going to domain.tld rather than host-name.domain.tld.

if you are concerned about search engine optimization (SEO): do not be. search engine "bots" start from the 'domain.tld' and DNS. also, they do not consider it a "good" thing when a server offers a re-direct. thus, prune your links and do the right thing in DNS and you will be much better off!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.