Redirect incorrect URL's

santoshsahoonis
Kilo Guru

Hello,

If a user types in a URL : instancename.service-now.com/<anything here>/

then servicenow opens the homepage with the url: instancename.service-now.com/<anything here>/navpage.do

I think Servicenow should have either corrected the URL or shown a 404 error page, but it doesnot.

I was thinking of using sendRedirect()   (Used in processing scripts for UI Pages) but don't know where to use this script to redirect wrong URL's to instancename.snow.com/navpage.do

Any suggestion would be appreciated.

5 REPLIES 5

will_leingang
ServiceNow Employee
ServiceNow Employee

Santosh, the first part of the path is basically inaccessible by app developers on the glide platform. It's a domain separation thing.



One possibility would be to create a ui script and make redirect decisions based on window.location.pathname but be careful because that will run on every page in the system and you might redirect when you don't mean to.



Will


Hey Will,



Thanks for your reply.



Domain separation comes into picture when you talk about domains and subdomains(This is not the issue here and its already handled by SNOW). Rewriting URL in server is done using htaccess or equivalent methods(depends on the web server) but we do not have access to it.



UI Scripts are not good solutions. Never use them unless it adds enough value to compensate for the disadvantages. And even if you use UI Script, there will be a unwanted redirect.



Since, this is best solved from server side, I was wondering if there are any properties in SNOW that are not documented in wiki and can be used for this.



Anyways, thanks for your response. Cheers!!


Hi Santosh, sorry I wasn't more clear, the domain separation I was referring to had nothing to do with the dns name, but the app domain separation in GlideServletRequestProvider.



I'm going to try something really quick to see if you can determine at the beginning of a GlideServletRequest if it's a 404 somehow.



More soon.


Will


Hi Santosh, Here's a thought.



If the users you are trying to redirect are authenticated, you could do this:



  1. Set the system property "glide.login.home" value to "not_found.do?sysparm_direct=true"
  2. Rename the current ui_page "not_found" to "not_found2"
  3. Create a new ui_page with the name "not_found" with the following attached html.

<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">


  <g:evaluate var="jvar_site_name" expression="GlideTransaction.get().getSiteName();" object="true"/>


  <j:if test="${jvar_site_name != null}">


  <g:evaluate var="jvar_redirect_url" jelly="true">


  var redirectLocation = jelly.jvar_site_name + '/' + jelly.sysparm_this_url.replace('not_found.do', '');


  redirectLocation;


  </g:evaluate>


  Do Javascript here to redirect to: ${jvar_redirect_url}


  </j:if>



  <j:if test="${jvar_site_name == null}">


  <j:choose>


  <j:when test="${sysparm_this_url == 'not_found.do?sysparm_direct=true'}">


  <script>


  window.location.href = 'home_splash.do';


  </script>


  </j:when>


  <j:otherwise>


  <g:inline template="page_not_found.xml" />


  </j:otherwise>


  </j:choose>


  </j:if>


</j:jelly>


Now customize the javascript where it says "Do Javascript here to redirect..."