Question

I have an external website which needs to show URL in lowercase only. I don’t want to use URL Rewrite or any third party tool. Instead we decided to change the actual URL’s of the Pages Library. I’ve done that by using the following script.

if ($list.RootFolder.Url.Equals("Pages"))
{
    $ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
    Write-Host $ListURL
    Write-Host "Title: " $list.Title ", Url: " $list.RootFolder.Url -foregroundcolor magenta

    #try 
    #{
        $list.Title = $list.Title.ToLower()
        $list.RootFolder.MoveTo($list.RootFolder.Url.ToLower())
    #}
    #catch [System.Management.Automation.RuntimeException] 
    #{
    #    write-host 'RuntimeException'
    #}

    $list.Update()

    Write-Host "Title: " $list.Title ", Url: " $list.RootFolder.Url -foregroundcolor darkgreen
}

if ($SPWeb -ne $null)
{
    $SPWeb.Dispose()
}

... which outputs ...

http://dev. ... /contact/Pages
Title:  Pages , Url:  Pages
RuntimeException
Title:  pages , Url:  pages

Yes, I get a Runtime Error, but the URL and list name actually changes (se image).

enter image description here

If I go to a page in the pages library directly, I get the new URL, but if I write the short hand URL (without /pages/default.aspx) I get the previous initial uppercase letter /Pages URL. My question is why, and how do I resolve this?

Was it helpful?

Solution

You are redirected to the Pages library instead of pages because there is a property on the web level, which holds the old URL of the default page. In order to fix this, you will need to insert the following snippet into your script:

$folder = $SPWeb.RootFolder;
$folder.WelcomePage = $folder.WelcomePage.Replace("Pages","pages");
$folder.Update();

I hope this helped. If not, please feel free to ask me for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top