title: How to get a valid Liferay Layout from a given URL
body: <p>The requirement is simple:</p>
  
  <p><strong>Given a URL, how to determine to which <code>Layout</code> it corresponds to?</strong></p>
  
  <p>The reason I need to do this is for certain layouts which meet specific conditions I need to redirect them to a certain other layout based on the roles/usergroups of a User. I am using a filter hook to achieve this.</p>
  
  <p>For eg:</p>
  
  <p>All these are same layouts:</p>
  
  <ul>
  <li><code>http://localhost:8080/web/guest/home</code> takes to the home page of guest</li>
  <li>Even <code>http://localhost:8080/home</code> also takes to home page of guest, if virtual host is set</li>
  <li><code>http://localhost:8080/web/guest/home?something=isSomething&amp;etc</code> also takes to home page</li>
  </ul>
  
  <p>Then there are other URL patterns similar to these but are used to serve CSS, JS and images from themes and then there are friendly URLs for different assets, for example:</p>
  
  <ul>
  <li><code>http://localhost:8080/combo?someparameters</code></li>
  </ul>
  
  <p>Currently I am getting the layout using string manipulation in the Filter hook, like getting the path element of the URL and then searching for friendly-url of the layout etc; but this approach seems to be error-prone at best.</p>
  
  <p>It would be good to know how liferay handles all these scenarios, any pointers to the code or approach would help.</p>
  
  <p>Thanks</p>