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 have the following rewrite rule setup:

rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://domain2.com/$1 [r=301,nc]

Now this works for redirecting domain.com/index.htm to domain2.com/index.htm however it won't redirect any folders e.g. domain.com/folder/ won't redirect to domain2.com/folder/

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

First advice: use proper lower/uppercase:

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://domain2.com/$1 [R=301,NC,L]

Then maybe you forgot the "L" for "Last rule".

When you say "it won't redirect any folders e.g. domain.com/folder/ won't redirect to domain2.com/folder/" please explain what it gives, what it should give, and what it give without the rewrite rules. Then I could help you further.

Two hints:


Please try to use the RewriteLog directive: it helps you to track down such problems:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

My favorite tool to check for regexp:

http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)

share|improve this answer
    
Another useful tip is to use curl -I http://example.com/foo or curl --include http://example.com/foo to test your rules. Doing this in a browser can result in several redirects happening with no hint that this is going on, leading to much confusion. –  Ladadadada Dec 8 '11 at 7:53
    
When I try view domain.com/folder/ it just does nothing, no redirect over to domain2.com, it just loads domain.com/folder/. domain.com/index.htm redirects to domain2.com/index.htm though. –  Luke Dec 9 '11 at 2:22
    
Looks like I had another .htaccess that was interfering with some folders. Thanks again for all your help. –  Luke Dec 12 '11 at 12:52
add 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.