title: Limit access to subdirectory via specific SERVER_PORT using htaccess
body: <p>I've been trying to limit access to a specific subdomain via the server port, e.g. it can only be accessed from subdomain.domain.com:8443 and no other ports.</p>
  
  <p>I'm currently using hostgator for my webhost, and it's already been setup such that subdomain.domain.com points to the correct subdirectory.</p>
  
  <p>Now in the htaccess file, I'm currently trying this:</p>
  
  <pre><code>Options +FollowSymLinks
  RewriteEngine on
  RewriteBase /subdomain
  RewriteCond %{SERVER_PORT} !^8443$
  RewriteRule   ^  -  [F]
  RewriteCond %{SERVER_PORT} ^8443$
  RewriteRule ^(.*)$ http://%{HTTP_HOST}/subdomain/$1 [R=301,L]
  </code></pre>
  
  <p>As far as the blocking of other ports goes, it seems to work since accessing either subdomain.domain.com or www.domain.com/subdomain, I get a 403 forbidden page. But I can't get it to load the normal content correctly when I do access it via subdomain.domain.com:8443 or www.domain.com:8443/subdomain. Am I doing the rewrite conditions and rules correctly?</p>
  
  <p>Thanks!</p>