start learning
7

htaccess configurations

Most usefull configurations

The .htaccess file is a configuration file that can be used on web servers running the Apache Web Server software. It allows webmasters to configure various server settings and enables the use of more advanced features on the server.

Here are some common .htaccess configurations that you can use on your website :
  1. Redirecting URLs: You can use the RewriteRule directive to redirect users from one URL to another. For example, you can redirect users from old URLs to new ones when you redesign your website.
  2. Blocking access to files and directories: You can use the Deny directive to block access to specific files or directories on your website.
  3. Password-protecting directories: You can use the AuthType directive to require users to enter a username and password to access certain directories on your website.
  4. Customizing error pages: You can use the ErrorDocument directive to create custom error pages for your website.
  5. Modifying server settings: You can use various directives to modify the server settings, such as the php_value directive to set PHP settings.
Here is a sample .htaccess file that includes some common configurations :

# Redirect all HTTP traffic to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

# Block access to the wp-config.php file
<files wp-config.php>
Order deny,allow
Deny from all
</files>

# Password-protect the admin directory
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpasswd
Require valid-user

# Custom error pages
ErrorDocument 404 /not-found.php
ErrorDocument 500 /internal-error.php

# Set PHP settings
php_value memory_limit 128M

Note that the exact configurations you need may vary depending on your specific website and server setup. You should always test any changes to your .htaccess file to ensure they are working as expected.