Mobile app version of vmapp.org
Login or Join
LarsenBagley505

: Prevent access via .htaccess *TO* a given hostname I have a website which is accessible via several hostnames. I would like to put something in an .htaccess file that would simply block any

@LarsenBagley505

Posted in: #Htaccess

I have a website which is accessible via several hostnames.

I would like to put something in an .htaccess file that would simply block any request requesting a particular hostname.

For example, say example1.com and hello.somehost.com both point to the same website. I would like to put something in the .htaccess file that will allow users to view the website if they visit example1.com, but will not allow users to view it if they visit hello.somehost.com.

You'd think this would be easy to Google but if there are any results out there, they're drowned out by people who want to block access if the user is coming from a particular hostname...

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @LarsenBagley505

2 Comments

Sorted by latest first Latest Oldest Best

 

@Megan663

You can implement it using mod_rewrite. Have mod_rewrite check for the HTTP_HOST and show a 403 Forbidden error:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^hello.somehost.com$
RewriteRule .* - [F]

10% popularity Vote Up Vote Down


 

@Moriarity557

Apparently newer versions of apache (2.4) support conditional statements in .htaccess files, although i havent found a reference... just lots of results on other stack exchange sites.

You might also be able to accomplish what you want to do using rewrite rules.

Otherwise, the most obvious place to do this is in your virtual host config.

If you have a global php include file, you could do it there as a last resort.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme