apache - how to config .htaccess to prevent www.parent.com/child access www.child.com -


i have unix shared hosting have:

/   .htaccess a.html .... child/    .htaccess    b.html    ...... 

the www.parent.com points /
www.child.com points /child

i have prevent access www.parent.com/child without stopping www.child.com working.
result can redirect, 404 or access denied.
.htaccess files based on html5boilerplate .htaccess file.

i tried modified /.htaccess without success:

attempt #1:

<directory /child>     order deny,allow     deny  </directory> 

--> child.com stopped working.

attempt #2:

 rewritecond %{http_host} ^.*parent.com.*$ [nc]  rewriterule ^.*/child.*$ / [nc] 

--> nothing happens. tried different regex combinations.

attempt #3:

  <ifmodule mod_rewrite.c>      rewritecond %{request_uri}   ^.*child.*$              [nc]      rewriterule ^    /   [r=302.l]         </ifmodule> 

--> nothing happens. known 1 brute force, after trying main less aggressive options.

i known rewriteengine on, because works:

<ifmodule mod_rewrite.c>      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] </ifmodule> 

you can use rule first rule inside /child/.htaccess:

rewriteengine on  rewritecond %{http_host} !^(www\.)?child\.com$ [nc] rewriterule ^ - [f,l] 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -