I would like to redirect all urls from the host a.myhost.com to b.myhost.com. I've explored all the options - Apache redirect, rewriterule directives. I want the redirects to happen to the same target url - which is http://b.myhost.com - regardless of what the original url was (e.g. a.myhost.com/a.html). All the examples that claim to be able to do this, actually don't, in practice (atleast on my Apache installation). The a.html is carried forward to the redirected host - which is not what is desired.

Any ideas?

  • can you possible tell if you have <Directory /> in your httpd.conf or inside your VirtualHost with AllowOverride and what is it set to ? it may be the cause why your mod_rewrite inst working.
    – Prix
    Commented Aug 22, 2010 at 7:55

3 Answers 3

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName a.example.com
  RedirectMatch .*$ http://b.example.com/

See http://httpd.apache.org/docs/current/mod/mod_alias.html#redirectmatch for details.

RewriteEngine On
RewriteRule ^(.*)$ http://b.myhost.com/ [R,L]

Does that work?

  • Thanks, but it doesn't - in fact, this is the most common example I've come across.
    – talonx
    Commented Aug 20, 2010 at 7:51

I belive something like this would do the job

RewriteEngine on
RewriteCond %{HTTP_HOST} ^a.example.com
rewriterule ^(.*)$ http://b.example.com$1 [R=301]
  • Thanks, but it doesn't. Am suspecting something with my Apache installation now.
    – talonx
    Commented Aug 20, 2010 at 7:55
  • @talonx then you don't have mod_rewrite enable at least.
    – Prix
    Commented Aug 20, 2010 at 7:57
  • Hmm...I checked - seems to be enabled.
    – talonx
    Commented Aug 20, 2010 at 8:37
  • what "seems to be enabled" means ? i am sorry but it is "yes, it is enabled" or "no, it is not". Have you looked into the httpd.conf file for the module load entry for mod_rewrite, have you check for the .ht entry aswell ? Can you update your answer with more information like how are you using the rules above, what and where the file is located etc ?
    – Prix
    Commented Aug 20, 2010 at 9:14
  • @Prix - sorry, my bad. It is enabled. The LoadModule entry is present, and so is the .htaccess entry (I assume that's what you meant). Thanks for the help.
    – talonx
    Commented Aug 20, 2010 at 10:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .