bider2k
asked on
Parse part of a path and redirect to another domain with that part
I have 2 domains: example1.com and example2.com.
On example2.com there are a bunch of vanity urls like example2.com/first.middle. last for thousands of people.
But, users keep going example1.com looking for the vanity urls, which don't exist there.
I need to figure out how to redirect users who go to example1.com looking for those vanity urls to example2.com with the vanity url --- without setting up the thousands of redirects on example1.com.
I don't have access to the server, so I'm thinking a javascript solution would work best. Some JS on the error page of example1.com that would parse the URL for the /first.middle.last pattern and redirect them to example2.com/first.middle. last.
On example2.com there are a bunch of vanity urls like example2.com/first.middle.
But, users keep going example1.com looking for the vanity urls, which don't exist there.
I need to figure out how to redirect users who go to example1.com looking for those vanity urls to example2.com with the vanity url --- without setting up the thousands of redirects on example1.com.
I don't have access to the server, so I'm thinking a javascript solution would work best. Some JS on the error page of example1.com that would parse the URL for the /first.middle.last pattern and redirect them to example2.com/first.middle.
ASKER
Cool. That will do the domain switch.
But since I need to put this on the example1.com's error page, I need to just execute this script when someone gets the 404 error when looking for a url with that pattern: example1.com/first.middle. last. The pattern would always have the 2 dots separating the first name, middle initial, and last name.
I don't want the redirect to happen when an actual 404 is generated --- say if a user requests a url that is actually not found like example1.com/about/contacc t.html.
But since I need to put this on the example1.com's error page, I need to just execute this script when someone gets the 404 error when looking for a url with that pattern: example1.com/first.middle.
I don't want the redirect to happen when an actual 404 is generated --- say if a user requests a url that is actually not found like example1.com/about/contacc
ASKER
I just put this on my IIS localhost error page, and it doesn't seem to be taking the vanity part of the URL when it does the redirect.
Do you have a link where I could see it in action? This might help to diagnose why it's not working;
ASKER
Oops, I was wrong. It is working. I just need to figure out how to parse the url for the first.middle.last pattern. Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is exactly it. Thank you so much!
<html>
<script type="text/javascript">
var url = document.location.href.rep
document.location.href=url
</script>
</html>
It pulls the address of the page, performs a search/replace on it, and refreshes the browser to the new page. This should keep your vanity URI intact on the new domain.
Open in new window