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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With