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've done a little research into ModRewrite rules and conditions but have not been able to find a satisfactory set of rules/conds which achieve the effect I'm looking for.

Essentially, I have a directory on domain A (http://www.domaina.com/dir/) which I would like to redirect to a different directory on domain B (http://www.domainb.com/diff_dir/).

Note that I only want to apply the rewrite rule if the user is attempting to access /dir/ on domaina. If they are accessing a different directory or root I do not want to rewrite the URL.

Thank you!

share|improve this question

1 Answer 1

In domaina config:

#redirect everything under dir to the same location under domainb.com/diff_dir
RewriteRule ^/dir/(.*)$ http://www.domainb.com/diff_dir/$1 [r=301]

#redirect url http://www.domaina.com/dir to http://www.domainb.com/diff_dir
RewriteRule ^/dir(/)?$ http://www.domianb.com/diff_dir [r=301]

I didn't test this, but it should work.

Note:
If you're doing this in the root .htaccess file or in a specific directory config you'll want to drop the leading '/' or otherwise adjust the rule pattern. Something like ^dir(/)?$.

share|improve this answer
    
You could put both rules into one line with something like RewriteRule ^/dir(/?|/.*)$ domianb.com/diff_dir$1 [r=301] –  matthew Jun 16 '10 at 18:24

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.