Implement a URL shortener URLs are getting too long. So, you must implement an algorithm to shorten a URL.

i. The Structure of a URL

A URL has 2 main parts: a domain and a path. A domain is the part of the URL before the first slash. You may assume that the URL does not include a protocol. The path is everything else.

ii. The Domain

The domain of a URL will be something like: xkcd.com meta.codegolf.stackexcchhannnge.cooom.  Each part is period-seperated, e.g. in blag.xkcd.com, the parts are "blag", "xkcd", and "com". This is what you will do with it:


If it contains more than two parts, put the last two aside and concatenate the first letter of the rest of the parts.
Then, concatenate that to the first letter to the second-to-last part.
Add a period and the second and third letter of the second-to-last part.
Discard the last part.


iii. The Path

The path will be like: /questions/2140/ /1407/. As before, "parts" are seperated by slashes.  For each part in the path, do:


Add a slash
If it is completely made of base-ten digits, interpret it as a number and convert to a base-36 integer.
Otherwise, add the first letter of the part.


At the end, add a slash.

iv. Misc.


This is code-golf, so shortest code wins.
The path can be empty, but the URL will always end with a slash.
There will not be a protocol (e.g. http://, file:///)
There will never be less than two parts in the domain.
Standard loopholes apply.


Examples

In: xkcd.com/72/
Out: x.kc/20/

In: math.stackexchange.com/a/2231/
Out: ms.ta/a/1pz/

In: hello.org/somecoolcodeintrepreteriijjkk?code=3g3fzsdg32,g2/
Out: h.el/s/
JavaScript (ES6), 149 bytes

u=&gt;u.split`/`.map((p,i)=&gt;i?/^\d+$/.test(p)?(+p).toString(36):p[0]:(d=p.split`.`).slice(0,-1).map((s,j)=&gt;s[l=j,0]).join``+"."+d[l].slice(1,3)).join`/`


Explanation

I made this independent of @Neil's solution but it ended up looking very similar.

u=&gt;
  u.split`/`.map((p,i)=&gt;       // for each part p at index i
    i?                         // if this is not the first part
      /^\d+$/.test(p)?         // if p is only digits
        (+p).toString(36)      // return p as a base-36 number
      :p[0]                    // else return the first letter
    :
      (d=p.split`.`)           // d = domain parts
      .slice(0,-1).map((s,j)=&gt; // for each domain part before the last
        s[l=j,0]               // return the first letter, l = index of last domain part
      ).join``
      +"."+d[l].slice(1,3)     // add the 2 letters as the final domain
  )
  .join`/`                     // output each new part separated by a slash


Test



var solution = u=&gt;u.split`/`.map((p,i)=&gt;i?/^\d+$/.test(p)?(+p).toString(36):p[0]:(d=p.split`.`).slice(0,-1).map((s,j)=&gt;s[l=j,0]).join``+"."+d[l].slice(1,3)).join`/`
&lt;input type="text" id="input" value="math.stackexchange.com/a/2231/" /&gt;
&lt;button onclick="result.textContent=solution(input.value)"&gt;Go&lt;/button&gt;
&lt;pre id="result"&gt;&lt;/pre&gt;