I need to redirect the subsite URL to Root site collection, For example, if I accessed the ~sitecollection/departments means, It needs to redirect to ~sitecollection, Is it possible? or Is it possible to create a virtual as sites/departments? I tried http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=48 this, but I am not clear, Please suggest me some idea to achieve this .
1 Answer
Add below code in your master page, this will redirect to root site if user try to access subsite.
$(document).ready(function() {
var siteUrl = _spPageContextInfo.siteServerRelativeUrl;
var webUrl = _spPageContextInfo.webServerRelativeUrl;
var isRootWeb = siteUrl == webUrl;
if(isRootWeb == false){
window.location.replace(_spPageContextInfo.siteAbsoluteUrl);
}
});