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

Will this redirect work [a-z]* to example.com

ie., I want to redirect anything to example.com

Thanks Jean

share|improve this question

2 Answers 2

Putting RedirectPermanent / http://example.com/ in your Apache httpd configuration should do the trick.

share|improve this answer

If you want to redirect anything to example.com, what you probably want is something like this:

RewriteRule ^[a-z]*$ http://www.example.com [R,L]

This will redirect ANY request made to the any part of your URL to http://www.example.com. I.e.,

http://mysite.com => http://www.example.com
http://mysite.com/asdasd => http://www.example.com
http://mysite.com/another/test => (not forwarded)
share|improve this answer
    
and if I want to redirect example.net to example.com, do I write something like this---------------------------><VirtualHost *:80> ServerName y.com ServerAlias *.y.com Redirect permanent / x.com </VirtualHost> –  Jean Nov 1 '10 at 7:23
    
I may have misunderstood your question. I thought you were only trying to forward requests that matched a pattern. If you just want to have the entire domain forwarded, joschi's answer is the better one. –  Andrew M. Nov 1 '10 at 7:26
    
my question stands as it is. But I got confused with the adding of virtual host in the httpd.conf and the rewriterule. I want to add it to the httpd.conf than to the www directory –  Jean Nov 1 '10 at 7:37
    
In the case of RewriteRule, you can add it inside or outside a VirtualHost directive. Adding it to the VirtualHost will only rewrite for requests matching that host. –  Andrew M. Nov 1 '10 at 7:46

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.