0

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/

Luke
  • 183
  • 11

1 Answers1

1

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)!)

Olivier Pons
  • 612
  • 1
  • 5
  • 21
  • 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 08 '11 at 07: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 09 '11 at 02: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