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 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?

share|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
add comment

3 Answers 3

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.

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

Does that work?

share|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
add comment

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]
share|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

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.