0

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

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

Thanks Jean

Jean
  • 261
  • 1
  • 7
  • 15

2 Answers2

1

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)
Andrew M.
  • 11,182
  • 2
  • 35
  • 29
  • and if I want to redirect example.net to example.com, do I write something like this---------------------------> ServerName y.com ServerAlias *.y.com Redirect permanent / http://x.com/ – Jean Nov 01 '10 at 07: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 01 '10 at 07: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 01 '10 at 07: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 01 '10 at 07:46
1

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

joschi
  • 21,387
  • 3
  • 47
  • 50