0

My urls are in this form

/sites/site-name/Subpath-2/page-name.page
/sites/site-name/Subpath-3/Subpath-4/index.page

And this should be rewritten as /sitename/subpath/pagename (the extention .page is removed) also the subpath can have multiple folders ie (/sites/site-name/Subpath-2/..../page-name.page)

If we have a url ending with index.page then we must remove the index.page eg:
/sites/site-name/...subpath.../index.page should be /sites/site-name/...subpath.../

I have tried using back references in this way

ProxyHTMLURLMap "\/sites\/([A-Za-z-0-9]+|-)\/([A-Za-z-0-9]+|-)\/([A-Za-z-0-9]+|-)\.page$" "/$1/$2/$3" R

And for urls ending with index

ProxyHTMLURLMap "\/sites\/([A-Za-z-0-9]+|-)\/([A-Za-z-0-9]+|-)\/(index)\.page$" "/$1/$2/" R

But I need to rewrite the URLs in such away that the subpaths can be many ie it should work for any urls which can have more that three subpaths it needs to work for /sites/site-name/Subpath-3/Subpath-4/index.page /sites/site-name/Subpath-1/Subpath-2/Subpath-3/home.page

1 Answers1

0
ProxyHTMLURLMap "\/sites((\/([A-Za-z-0-9]+|-))*)\/([A-Za-z-0-9]+|-)\.page$" "$1/$4" R

Breaking that apart:

  • ((\/([A-Za-z-0-9]+|-))*) is any number of path components - zero or more - following /sites. Each component begins with /. The whole string of all of the path components is stored in $1.
  • At the end is ([A-Za-z-0-9]+|-)\.page$, the file name ending in .page. Its result is stored in $4, because it starts with the 4th open parenthesis in the expression.

If you want to require at least one path component between /sites and the file name, instead of zero or more, you can change the * to a +.

Andrew Schulman
  • 8,811
  • 21
  • 32
  • 47