Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  128] [ 6]  / answers: 1 / hits: 27974  / 11 Years ago, fri, august 2, 2013, 12:00:00

If someone types in 'www.morgancc.edu', I want it to redirect to our mobile site located at 'www.morgancc.edu/m' However, I only need to redirect with this exact URL. I don't want it to redirect if you go to something like 'www.morgancc.edu/programs', which is what it is currently doing. Here is the code I have so far:



<script type=text/javascript>
if (window.location = www.morgancc.edu) {
window.location.href = 'http://www.morgancc.edu/m/';
}
</script>

More From » redirect

 Answers
69

location.hostname with an empty path is what you seem to want



if (window.location.hostname == www.morgancc.edu && 
window.location.pathname== ) {
window.location.href = 'http://www.morgancc.edu/m/';
}


Alternatively look at the href



if (window.location.href== http://www.morgancc.edu) {
window.location.href = 'http://www.morgancc.edu/m/';
}


You may need to add some / here or there


[#76555] Friday, August 2, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaden

Total Points: 709
Total Questions: 91
Total Answers: 91

Location: Maldives
Member since Sat, Jan 29, 2022
2 Years ago
jaden questions
Tue, Jun 29, 21, 00:00, 3 Years ago
Sun, Jul 5, 20, 00:00, 4 Years ago
Fri, May 29, 20, 00:00, 4 Years ago
Wed, May 27, 20, 00:00, 4 Years ago
;