How to set apache configurations in .htaccess file?

by scotty_walker , in category: Third Party Scripts , 3 months ago

How to set apache configurations in .htaccess file?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by cali_green , 3 months ago

@scotty_walker 

To set Apache configurations in a .htaccess file, you can use directives that modify the behavior of Apache web server. Here is a simple guide on how to set up common configurations in .htaccess file:

  1. Enable/disable directory browsing: To disable directory browsing, add the following line to your .htaccess file: Options -Indexes
  2. Redirect URLs: To redirect incoming requests from one URL to another, use the following syntax: Redirect /old-url /new-url
  3. Set custom error pages: To set up custom error pages, use the ErrorDocument directive followed by the HTTP status code and the path to the custom error page: ErrorDocument 404 /errors/404.html
  4. Password protect a directory: To password protect a directory, use the following directives: AuthType Basic AuthName "Restricted Area" AuthUserFile /path/to/.htpasswd Require valid-user
  5. Disable hotlinking: To prevent other websites from hotlinking your images or files, add the following lines to your .htaccess file: RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www.)?yourwebsite.com/ [NC] RewriteRule .(jpg|jpeg|png|gif)$ - [F]


Remember to always backup your .htaccess file before making any changes, as incorrect configurations can cause issues with your website.