: Redirect loop from two domain using the same .htaccess 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
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/ www.website2.com/example/, there will be a redirect loop.
It will redirect www.website1.com/example/ to www.website2.com/example/.
Then also redirect www.website2.com/example/ to www.website2.com/example/ (which creates the redirect loop)
What I want is to somehow only redirect www.website1.com/example/ to 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.
More posts by @XinRu657
1 Comments
Sorted by latest first Latest Oldest Best
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/(.*)$ www.website2.com/example/ [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 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. www.website1.com/ to www.website2.com/, you can use something like the following:
RewriteCond %{HTTP_HOST} ^(www.)?website1.com$ [NC]
RewriteRule ^$ 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.)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.