How to Disallow URLs in .htaccess


Disallowing traffic from specific URLs to your website might be necessary for a number of reasons. For instance, you might not want traffic from a specific search engine or a particular URL that spams your comment section. Regardless of the reason, it is possible to disallow any traffic from a specific URL or group of specific URLs using the .htaccess file. .Htaccess files allow you to make configuration and access changes, such as disallowing URLs, when you don't have direct access to the server configuration files, which is the case with nearly everyone using third-party web hosting.

Things You'll Need

  • FTP client software
  • Code-editing software
  • Download your ".htaccess" file from your Drupal site files using your FTP client software. Dreamweaver, Internet Explorer or FileZilla will work. If you do not have a .htaccess file, continue to Step 2.

  • Open your .htaccess file with your code-editing software. Notepad will work if you do not have other code software. If you do not have a .htaccess file, open a blank document and save it as ".htaccess."

  • Add the following code to your .htaccess file:

    RewriteEngine on

    RewriteCond %{HTTP_REFERER} ^http://.*DisallowedURL\.com [NC]

    RewriteRule .* - [F]

    Place it at the bottom of the file if you have an existing .htaccess file.

  • Save your .htaccess file and upload it to your website files. If this is a new file, upload it to the root directory of your website files. The URLs specified will now be disallowed.

Tips & Warnings

  • To disallow multiple URLs, end each "RewriteCond" entry with "[NC, OR]" and end your last entry with just "[NC]."
  • You can also use a "403 access denied error" in your .htaccess file to disallow URLs.


  • Photo Credit Jupiterimages/ Images
Promoted By Zergnet


Related Searches

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!