1

How our FTP was setup, the root level is Website #1. Website #2 has it's own directory folder inside that root.

Both websites refer to the same .htaccess.

If I do Redirect 301 /example/ http://www.website2.com/example/, there will be a redirect loop.

It will redirect http://www.website1.com/example/ to http://www.website2.com/example/.

Then also redirect http://www.website2.com/example/ to http://www.website2.com/example/ (which creates the redirect loop)

What I want is to somehow only redirect http://www.website1.com/example/ to http://www.website2.com/example/ without creating the redirect loop.

NOTE: I do NOT want every webpage on Website#1 to redirect to Website#2. Just that specific URL to the new URL.

1 Answer 1

1

You'll need to use mod_rewrite (as opposed to a mod_alias Redirect) and check the HTTP_HOST server variable (which tells you which site has been accessed). Something like the following at the top of your .htaccess file:

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

Change the 302 (temporary) to a 301 (permanent) redirect if you need a permanent redirect, but only after you have tested to make sure it's working OK. (301 redirects are cached by the browser so can make testing problematic - unless you test with the browser cache disabled.)

This redirects /example/<something> to http://www.website2.com/example/<something>, in much the same way as the original Redirect directive would do (which is prefix matching).


UPDATE: To redirect just the homepage, ie. http://www.website1.com/ to http://www.website2.com/, you can use something like the following:

RewriteCond %{HTTP_HOST} ^(www\.)?website1\.com$ [NC]
RewriteRule ^$ http://www.website2.com/ [R=302,L]

Note the RewriteRule pattern ^$ - this matches the empty URL (ie. the homepage only). (Note that the URL matched by the RewriteRule pattern is less the directory-prefix.)

2
  • 1 more question: How do I redirect; just the homepage. Website1 homepage, to Website2 homepage? I tried doing the same way, but it is redirecting everything, to the equivalent version.... Do I need to wrap it in quotes or something? So it's exact match redirect?
    – Michael
    Jun 22, 2016 at 18:29
  • 1
    I've updated my answer. I assume there's no example subdirectory this time - literally just the document root - one domain to the other.
    – MrWhite
    Jun 22, 2016 at 18:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.