title: Safest way to get current page in Wordpress through $_SERVER
body: <p>I need to determine a redirect to another page very early in WP loading, specifically within <code>init</code> hook. For anyone familiar, at <code>init</code> hook, no global variables, like <code>$pagenow</code> or <code>$wpdb</code>, are set or initialized yet. So I have to rely on <code>$_SERVER</code> superglobal to determine the current page. But which of the various <code>$_SERVER</code> variables is the safest to use? I'm reading that some don't exist at specific environments. I checked mine, and I got the following results...</p>
  <ul>
  <li><code>['REQUEST_URI']</code> &lt;- current page, also contains the query string, ie. <code>/current-page/?some-query-string</code></li>
  <li><code>['REDIRECT_URL']</code> &lt;- clean current page, ie. <code>/current-page/</code></li>
  <li><code>['SCRIPT_URI']</code> &lt;- full URL, doesn't contain the query string, ie. <code>https://my-domain.tld/current-page/</code></li>
  <li><code>['SCRIPT_URL']</code> &lt;- clean current page, ie. <code>/current-page/</code></li>
  <li><code>['REDIRECT_SCRIPT_URI']</code> &lt;- full URL, doesn't contain the query string, ie. <code>https://my-domain.tld/current-page/</code></li>
  <li><code>['REDIRECT_SCRIPT_URL']</code> &lt;- clean current page, ie. <code>/current-page/</code></li>
  </ul>
  <p>What I need is the current page, free of query-strings, etc, so anything like <code>REDIRECT_URL</code>, <code>SCRIPT_URL</code>, <code>REDIRECT_SCRIPT_URL</code> are fine, but which of the three is the safest to use?</p>
  <p>Thank you in advance for any answer.</p>