[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Parse part of a path and redirect to another domain with that part

Posted on 2009-12-21
7
Medium Priority
?
243 Views
Last Modified: 2012-05-08
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.  

0
Comment
Question by:bider2k
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:uk44
ID: 26098161
Something like this should work for you.

<html>
<script type="text/javascript">
var url = document.location.href.replace('location1','location2');
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.
<html>
<script type="text/javascript">
var url = document.location.href.replace('location1','location2');
document.location.href=url;
</script>
</html>

Open in new window

0
 

Author Comment

by:bider2k
ID: 26098727
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/contacct.html.

0
 

Author Comment

by:bider2k
ID: 26098906
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:uk44
ID: 26098934
Do you have a link where I could see it in action? This might help to diagnose why it's not working;
0
 

Author Comment

by:bider2k
ID: 26099868
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?
0
 
LVL 1

Accepted Solution

by:
uk44 earned 500 total points
ID: 26099996
You could use something like this to count the number of dots after the last slash in the name.

The sample counts ensures there are two dots and if so, does the redirect (otherwise doesn't).

Is this what you were looking for?



<html>
<script type="text/javascript">
var uripath=document.location.href.replace(/^.*\//g,"");
if (uripath.match(/\./g).length==2)
{
	var url = document.location.href.replace('location1','location2');
	document.location.href=url;
}
</script>
</html>

Open in new window

0
 

Author Closing Comment

by:bider2k
ID: 31668612
That is exactly it.  Thank you so much!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question