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.

So I'm trying to write a mod_rewrite rule that will send everything on my main domain to a subdomain.

For example, redirect

http://example.com/1/2/3/4/5?n=6&i=7

to

http://sub.example.com/1/2/3/4/5?n=6&i=7

Here's what I have so far:

RewriteEngine On
RewriteCond ^http://www\.example.com\/ [NC]
RewriteRule ^(.*)$ http://sub.example.com/$1 [R=301,L]

But it doesn't seem to working. Any tips?

share|improve this question
    
    
@Shane Madden - don't think it's a dupe myself. That linked q is very helpful, but since it doesn't cover this specific question I think it is useful in its own right. –  Gavin C May 23 '11 at 22:24
1  
@Gavin Fair point. That question could use a wider breadth of examples, it's a little heavy on referrer examples at the moment. –  Shane Madden May 24 '11 at 0:46

1 Answer 1

I think you're missing something in your RewriteCond line. Try this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://www\.example.com\/ [NC]
RewriteRule ^(.*)$ http://sub.example.com/$1 [R=301,L]

So add the %{HTTP_HOST} into your RewriteCond rule... Note that I haven't tested this, so please post the results...

share|improve this answer

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.