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?

link|improve this question
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 Aug 22 '10 at 7:55
feedback

3 Answers

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

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

link|improve this answer
feedback
RewriteEngine On
RewriteRule ^(.*)$ http://b.myhost.com/ [R,L]

Does that work?

link|improve this answer
Thanks, but it doesn't - in fact, this is the most common example I've come across. – talonx Aug 20 '10 at 7:51
feedback

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]
link|improve this answer
Thanks, but it doesn't. Am suspecting something with my Apache installation now. – talonx Aug 20 '10 at 7:55
@talonx then you don't have mod_rewrite enable at least. – Prix Aug 20 '10 at 7:57
Hmm...I checked - seems to be enabled. – talonx Aug 20 '10 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 Aug 20 '10 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 Aug 20 '10 at 10:01
show 1 more comment
feedback

Your Answer

 
or
required, but never shown

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