0
votes

I have two different domains. Lets call them domain1 and domain2.

I need to mod rewrite:

www.domain1.com/some/stuff/after-domain

so that it becomes:

www.domain2.com/some/stuff/after-domain

Basically, everything after the domain should remain the same. The only difference should be changing the domain names. Can anyone help me with the rewrite rules for this. I've tried the following, but it's not working for me.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.domain2.com$
  RewriteRule ^(.*)$ http://www.domain1.com/$1 [R=301,L]
</IfModule>

Also, please note, that {REQUEST_URI} and {REQUEST_FILENAME} will not work for this application.

Thank you in advance, as always.

EDIT: Per the request for more info, the result I get when using the rule above: http://www.domain1.comhttp//www.domain1.com/some/stuff/after-domain

Additionally, I forgot to specify that I'd like the domain1 to appear in the address bar URL, but pull content based on domain2 (is this even possible?)

2
What do you mean by not working? Does it give an error? Does it just not do anything? Is AllowOverride enabled in apache config? Need more info.Panama Jack
Updated per your requestbrybott

2 Answers

0
votes

I've assumed a general case where you want to redirect everything to one domain, so that you don't need to specify every possible permutation:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain1.com$
RewriteRule ^(.*)$ http://www.domain1.com$1

That should achieve what I think you're trying to do.

0
votes

The following should work for you:

RewriteEngine On
Redirect 301 / http://www.domain2.com/

It should redirect: www.domain1.com/some/stuff/after-domain -> www.domain2.com/some/stuff/after-domain