Link to home
Start Free TrialLog in
Avatar of Ralf Klatt
Ralf KlattFlag for Germany

asked on

.htaccess -> leading visitors from "old domains" to the desired products on "new domains"

Hi,

I am transferring contents of some domains to some other domains and I'd like (until February 2006) to lead all visitors still comming to the old domains to be directed to the desired products on the new domains ... I'm currently using this script in my .htaccess file:

# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName MyOldDomain.com
AuthUserFile /pages/77/f99999999/htdocs/_vti_pvt/service.pwd
AuthGroupFile /pages/77/f99999999/htdocs/_vti_pvt/service.grp
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^.*\.MyOldDomain.com/.*$ [NC]
ReWriteRule .*\.*$ http://www.MyNewDomain.com/ [R,L]

... but id doesn't do the trick -> what it does is obvious, it only rewrites the referrer in a permanent way to the starting page of the new domain -> my question is thus, is it possible to only rewrite ...

MyOldDomain.com to MyNewDomain.com

... and keep the pages constant?

Like, someone coming in from:

http://www.MyOldDomain.com/MyProducts/product777.html

Would reach at:

http://www.MyNewDomain.com/MyProducts/product777.html


Best regards,
Raisor
Avatar of slyong
slyong

This might work.  Never been tested.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^.*\.MyOldDomain.com/.*$ [NC]
RewriteRule (.*\.*)$ http://www.MyNewDomain.com/$1 [R,L]
ASKER CERTIFIED SOLUTION
Avatar of slyong
slyong

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ralf Klatt

ASKER

Hi,

Thanks a lot for your suggestions!

The first suggested solution led to "path not found" error on MyOldDomain.com

The second suggestion led to "file not found" on MyOldDomain.com


Best regards,
Raisor
Hi Raisor,

My bad, didn't test it properly.  Ok here's the solution:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com [NC]
RewriteRule ^/(.*)  http://www.newdomain.com/$1 [L,R]
Hi,

I've just tested your provided solution ... I'm sorry to say, it didn't do anything at all!

Spending the past two hours with trying this and trying that, I came to this workarround which propably is only possible to use because all (about 30.000 files) are HTM and HTML files and they are in only one main directory on my old domain as well as on my new domain:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ^(.*).htm [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^(.*).html [NC]
RewriteRule ^(.*) http://www.MyNewDomain.com/$1

... <-- and that does the trick I was looking for!

I'm sorry that none of your suggestions worked out for me ... but I'll give you a "B" degree for your very informing explanation at https://www.experts-exchange.com/questions/21528053/htaccess-leading-visitors-from-old-domains-to-the-desired-products-on-new-domains.html#14680277


Thanks for your time!
Best regards,
Raisor
Hi,

Just to add the fix of a bug:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ^(.*).htm [NC,OR]
RewriteCond %{REQUEST_FILENAME} ^(.*).html [NC,OR]
RewriteCond %{HTTP_REFERER} !^.*\.MyOldDomain.com/.*$ [NC]
RewriteRule ^(.*) http://www.MyNewDomain.com/$1

To explain:
Without the line ... RewriteCond %{HTTP_REFERER} !^.*\.MyOldDomain.com/.*$ [NC] ... no redirect happend when someone came in only from "http://www.MyOldDomain.com" and not with a file extension like ".htm" or ".html" -> instead there was a "No Access Error" thrown!


Best regards,
Raisor