I want to redirect a sites homepage to a subsites homepage. I can create a page from redirect page layout BUT, i want no waiting for a couple of seconds, i want immediate redirect. How can i achieve this?
-
3My experience is that the Redirect layout is immediate for end users who do not have edit rights to the page. Is this not the case?– user39209Commented Jun 3, 2015 at 21:21
-
1What access rights do you have? Are you an end user with edit privleges? Do you have access to the farm's server? Or somewhere in between?– ShooShoShaCommented Sep 8, 2017 at 17:31
5 Answers
It could be achieved with HTTP Redirect in IIS using IIS URL Rewrite module. This module allows to create various rule actions including redirect and request abort.
For your scenario i recommend this option because this should redirect the request faster as the redirection happens as soon as the HTTP request received by IIS.
Configuration
Let's describe how to configure Rule that redirect a sites homepage to a subsites homepage in URL Rewrite.
For example to redirect request from:
http://{ServerName}/teamsite/SitePages/Home.aspx
to:
http://{ServerName}/teamsite/itdepteamsite/SitePages/Home.aspx
the following Rule is used
,where
Pattern: ^(.*/)?teamsite/SitePages/home.aspx$
Redirect URL: teamsite/itdepteamsite/SitePages/Home.aspx
-
1Where do I find this setting? How would I go about adding these settings?– AksCommented Dec 15, 2016 at 11:56
-
1+1 for server redirect as the request cannot be handled any sooner. Commented Sep 8, 2017 at 17:30
You can use a standard HTML redirect with a wait period of 0:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Redirecting...</title>
<meta http-equiv="REFRESH" content="0;url=http://www.yoururl.com">
</head>
<body>
</body>
</html>
Changing the value of x
in content="x;url"
determines the number of seconds to wait before redirecting.
See: Redirect default.aspx or change default landing to page in _layouts folder?
-
this solution is not suitable for my case, because i will do set this redirection on any subsites created automatically.– ozdoganCommented Nov 14, 2012 at 17:29
-
this solution is not suitable for my case, because i will do set this redirection on any subsites created automatically.
Only one way to go then. You'll have to create an EventReciever which will trigger on WebProvisioned. The code will run every time a new subsite is created. You can find quiet a lot of information regarding this on Google.
Update
public override void WebProvisioned(SPWebEventProperties properties)
{
SPWeb currentWeb = properties.Web;
if (PublishingWeb.IsPublishingWeb(currentWeb))
{
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(currentWeb);
//Get the file name
SPFile welcomeFile = currentWeb.GetFile(pageName);
//Assign the new filename to the DefaultPage property
pubWeb.DefaultPage = welcomeFile;
//Update the Publishing Web.
pubWeb.Update();
}
}
-
thank you, that was really helping. and what to do in webprovisioned event?– ozdoganCommented Nov 15, 2012 at 8:14
-
1@ozdogan Please check my updated answer.– user2536Commented Nov 15, 2012 at 8:39
-
thanks. and something more, what will be the myhomepage.aspx ? is it a page created from "redirect page layout" or some aspx file containing the redirection html tags?– ozdoganCommented Nov 15, 2012 at 15:02
-
@ozdogan I'd say a Redirect Page Layout" as they are ment for that purpose :)– user2536Commented Nov 15, 2012 at 17:24
-
thanks but you miss something. i want immediate redirection. in redirect page layout, it waits for 5 seconds.– ozdoganCommented Nov 15, 2012 at 17:31
Perhaps you can change the Welcome page to subsite homepage. To do this Go to Site Settings > Look and Feel -> Welcome Page
-
2Which can also be set using PowerShell :
(get-spweb http://yourwebapp).RootFolder.Properties["vti_welcomepage"]
, or from SharePoint Designer.– Steve BCommented Nov 14, 2012 at 15:52 -
this solution is not suitable for my case, because i will do set this redirection on any subsites created automatically.– ozdoganCommented Nov 14, 2012 at 17:25
Another cool solution I found is this:
Changing the Timeout Value for a SharePoint Redirect Page
Short: Make a copy of the Redirect Page Layout and change the "SecondsBeforeRedirect" attribute from 5 to 0 in the source code
<PublishingWebControls:RedirectControl SecondsBeforeRedirect="0" runat="server"/>
This solution also has a latency time sadly