<p>First set your web server up so the full website gets loaded from both the external ports (e.g. 80 and 443) as well as your internal port (let's say 9001).</p>

<p>Then open your index.php file, and add this to the top of it:</p>

<pre class="lang-php prettyprint-override"><code>// Restrict CP access to port 9001
if (
    $_SERVER['SERVER_PORT'] != 9001 &amp;&amp; 
    isset($_GET['p']) &amp;&amp;
    preg_match('^\/*admin(\/.*)?$/', $_GET['p'])
) {
    http_response_code(403);
    echo 'You are not authorized to access this area.';
    exit();
}
</code></pre>

CC BY-SA 3.0
2015-11-17T11:59:32.873Z
2015-11-17T11:59:32.873Z
Brandon Kelly
<p>Is it possible to limit access to the Control Panel to a specific HTTP port, which is shielded from public access? We want external visitors to only be able to access the front end site.</p>

<security><authentication>
How can I restrict access to the Control Panel to a single port?
# How can I restrict access to the Control Panel to a single port?

(Asked by: username_0 on 2015-11-17)

Is it possible to limit access to the Control Panel to a specific HTTP port, which is shielded from public access? We want external visitors to only be able to access the front end site.

**Tags:** security, authentication

---

## 1 answers

### Answer by username_1 on 2015-11-17. Score: 2 | Accepted answer

First set your web server up so the full website gets loaded from both the external ports (e.g. 80 and 443) as well as your internal port (let's say 9001).
Then open your index.php file, and add this to the top of it:
// Restrict CP access to port 9001
if (
    $_SERVER['SERVER_PORT'] != 9001 && 
    isset($_GET['p']) &&
    preg_match('^\/*admin(\/.*)?$/', $_GET['p'])
) {
    http_response_code(403);
    echo 'You are not authorized to access this area.';
    exit();
}


---

