UbuntuCafe: htaccess | Daily News and Tips about Linux, Amazon, Ubuntu, Android.

Map Apache virtualhost to a subdirectory of another virtualhost using .htaccess

This can actually be accomplished using a single <VirualHost/>, by using the ServerAlias directive. You can then use the RewriteRule to pass those requests to the proper directory, and by leaving off [R] you will just be rewriting the request, leaving the URL intact.

map apache virtualhost


<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName example1.com
    ServerAlias example2.com

    <Directory /var/www/example1>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>

    DocumentRoot /var/www/example1

    RewriteEngine On
    RewriteCond %{HTTP_HOST} example2\.com [NC]
    RewriteRule (.*) /example2$1 [L]

</VirtualHost>

Or remove highlighted code from above VirtualHost and add the below code to .htaccess of example1's root directory.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} example2\.com [NC]
    RewriteRule (.*) /example2$1 [L]

How to protect website from hackers or block Web Security Scanners from Scanning your website for vulnerabilities

A web application security scanner is a program which communicates with a web application through the web front-end in order to identify potential security vulnerabilities in the web application and architectural weaknesses. It performs a black-box test. Unlike source code scanners, web application scanners don't have access to the source code and therefore detect vulnerabilities by actually performing attacks. Pentesters or Hackers use web security scanner to scan the website for security bugs in web applications and services.
disable hacking protect website from haching

The objective of web scanning can differ from hacking to securing the website. Web security scanner creates a mess on the targeted server and use heavy bandwidth of the server during scanning process.

Now I am going to show how to block Web Security Scanners from Scanning your website for vulnerabilities from hackers.

Just add the below script in to the .htaccess file of your website and it will block the security scanners like w3af, Acunetix, nessus, SQLmap etc.

RewriteEngine On
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_USER_AGENT} ^w3af.org [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^w3af.sourceforge.net [NC,OR]
RewriteCond %{HTTP_USER_AGENT} dirbuster [NC,OR]
RewriteCond %{HTTP_USER_AGENT} nikto [NC,OR]
RewriteCond %{HTTP_USER_AGENT} SF [OR]
RewriteCond %{HTTP_USER_AGENT} sqlmap [NC,OR]
RewriteCond %{HTTP_USER_AGENT} fimap [NC,OR]
RewriteCond %{HTTP_USER_AGENT} nessus [NC,OR]
RewriteCond %{HTTP_USER_AGENT} whatweb [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Openvas [NC,OR]
RewriteCond %{HTTP_USER_AGENT} jbrofuzz [NC,OR]
RewriteCond %{HTTP_USER_AGENT} libwhisker [NC,OR]
RewriteCond %{HTTP_USER_AGENT} webshag [NC,OR]
RewriteCond %{HTTP:Acunetix-Product} ^WVS
RewriteRule ^.* http://127.0.0.1/ [R=301,L]
</IfModule>