title: .htaccess domain redirection to folder but preventing direct access with 404
body: <p>I have a shared hosting in which I want to host several websites. To this end, and to keep things clear, I have redirected my primary domain (i.e. www.mydomain.com) to a folder (i.e. /mydomain.com/). However, I want to prevent direct access to this folder (www.mydomain.com/mydomain.com/) from the URL with a 404 error (not found).</p>
  
  <p>This is the .htaccess in the root directory:</p>
  
  <pre><code>RewriteEngine On
  RewriteBase /
  
  RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
  RewriteCond %{REQUEST_URI} !^/mydomain.com/0.1/$ [NC]
  RewriteRule ^(.*)$ /mydomain.com/0.1/$1
  RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ [NC]
  RewriteRule ^(/)?$ mydomain.com/0.1/index.php [L]
  
  RewriteCond %{THE_REQUEST}% ^[A-Z]{3,9}\ /mydomain\.com/ [NC]
  RewriteRule . - [R=404,L]
  </code></pre>
  
  <p>And this is the .htaccess in /mydomain/ with a bunch of rules for nice and tidy URLs.</p>
  
  <pre><code>RewriteEngine On
  RewriteRule ^about/(.+) index.php?a=about&amp;b=$1
  RewriteRule ^services/(.+) index.php?a=services&amp;b=$1
  </code></pre>
  
  <p>Right now this is the result:</p>
  
  <p>Accessing www.mydomain.com shows the content in /mydomain/ as hoped. However, www.mydomain.com/mydomain/ is also displayed, ignoring the 404 rule, and creating another folder -whatever the name- without an htaccess DOES throw the 404.</p>
  
  <p>I've been dealing with this problem for 5 days now and tried everything. At this point I don't know if the error comes from the root .htaccess or the folder's.</p>
  
  <p>Thanks in advance.</p>
  
  <p>PS: Just to be clear, I have no control over the httpd.conf file.</p>
  
  <hr>
  
  <p>Notes:</p>
  
  <ol>
  <li>I forgot saying that there is an additional folder inside /mydomain.com/ called /0.1/ for version control.</li>
  <li>If a include "RewriteOptions Inherit" after "RewriteEngine On" in the /mydomain.com/0.1/ htaccess, I get a 500 internal server error.</li>
  <li>Deleting the /mydomain.com/0.1/ htaccess file altogether will produce the desired 404 error for www.mydomain.com/mydomain.com/0.1/ and produce a 505 in www.mydomain.com</li>
  </ol>