how to config .htaccess to prevent www.parent.com/child access www.child.com <p>I have a unix shared hosting where I have: </p> <pre><code>/ .htaccess a.html .... child/ .htaccess b.html ...... </code></pre> <p>The www.parent.com points to /<br> The www.child.com points to /child </p> <p>I have to prevent the access to www.parent.com/child without stopping www.child.com from working.<br> The result can be a redirect, a 404 or access denied.<br> The .htaccess files are based on the html5boilerplate .htaccess file. </p> <p>I tried modified the /.htaccess without success:</p> <p>Attempt #1:</p> <pre><code>&lt;Directory /child&gt; Order Deny,Allow Deny from all &lt;/Directory&gt; </code></pre> <p>--> The child.com stopped working. </p> <p>Attempt #2:</p> <pre><code> RewriteCond %{HTTP_HOST} ^.*parent.com.*$ [NC] RewriteRule ^.*/child.*$ / [NC] </code></pre> <p>--> Nothing happens. I also tried different regex combinations. </p> <p>Attempt #3:</p> <pre><code> &lt;IfModule mod_rewrite.c&gt; RewriteCond %{REQUEST_URI} ^.*child.*$ [NC] RewriteRule ^ / [R=302.L] &lt;/IfModule&gt; </code></pre> <p>--> Nothing happens. I known this one is brute force, but it was after trying main less aggressive options. </p> <p>I known that RewriteEngine is on, because this works: </p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteCond %{HTTP_HOST} !=localhost [NC] RewriteCond %{HTTP_HOST} !=127.0.0.1 RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] &lt;/IfModule&gt; </code></pre>