1

I have multiple domains pointing to the same site.

Example:

I have www.admin-domain.com pointing to /var/www

I have www.test.com pointing to /var/www/test directory and this is OK.

Example:

www.admin-domain.com/test shows the same content as www.test.com

Using a .htaccess file how do I block www.admin-domain.com/test ?

4 Answers 4

1

Create a .htaccess in the "test" directory with the following contents:

RewriteEngine On
RewriteCond %{HTTP_HOST} !www.test.com$
RewriteRule (.*) - [F]

If the vhost accessing the file isn't www.test.com then the server will return a 403 Forbidden message.

1
  • The literal dots in the hostname (CondPattern) should really be backslash escaped and a start-of-string anchor should be used, ie. !^www\.test\.com$. And no need to capture the RewriteRule pattern here, ie. (.*) should simply be .*.
    – MrWhite
    Mar 14, 2018 at 18:38
0

Drop a .htaccess file into /var/www with belows content:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.admin-domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/test/.*
RewriteRule ^(.*)$ - [F,L]

but your example seems to contradict to what you said before.

1
  • I tried as you said but I still have access to <code>www.admin-domain.com/test</code>
    – stevs986
    Nov 3, 2011 at 16:07
0

in regards to the question and comments above I am using code below successfully, but would like to allow access from any folder named paypal under the specific domain - to any folder named download under the same domain. Can this code be altered to reside in the "sales" folder - and allow access from any folder inside it named paypal to any folder in it named download - regardless of where they reside inside the sales folder? ie. - allow access from any of these urls -

mydomain.com\sales\wherever\paypal\
mydomain.com\sales\whoever\anywhere\paypal\
mydomain.com\sales\whatumacallit\somewhere\else\paypal\

and many more

ie. - to any of these urls - while blocking anything that isn't from mydomain.com\sales

mydomain.com\sales\wherever\download\
mydomain.com\sales\whoever\anywhere\download\
mydomain.com\sales\whatumacallit\somewhere\else\download\

and many more

- currently I place place htaccess in each download folder to block access from everywhere except specific paypal folder url

RewriteEngine On
RewriteCond %{HTTP_HOST} !mydomain.com\sales\myplans\paypal\$
RewriteRule (.*) - [F]
  • Successfully using in each download folder but would like ANY folder named "download" to allow access from ANY folder named "paypal" under the specific domain sales folder only - "mydomain.com/sales"

something to place in sales folder that allows any folder inside it named download to have access from any folder inside it named paypal

So is it possible, I'm a rookie in htaccess but if this can be done it eliminates hundreds of htaccess files reducing them to one htaccess file! Sorry for all the text just trying to be very clear as to what I want to accomplish... Thanks

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – Dave M
    Mar 8, 2022 at 12:48
0

You could use the require directive in your .htaccess file (in www.admin-domain.com/test) to block access to specific domains:

Require host thisdomain.com
Require not host thatdomain.com this.otherdomain.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .