Everything You Need to Know About .htaccess File

In the computing world, the abbreviation of Hypertext Access is .htaccess file [configuration file]. It controls the response of webserver to various requests. .htaccessfile is used in multiple web servers including Apache webserver software. If you use CMC like Joomla, WordPress or Drupal, you will encounter. htaccessfile. It helps to edit the codes on the server-side.

Where is the .htaccess file located?

Theoretically, every directory or folder on your server can have one. In general, there is one located in the webroot folder, which holds website content and labeled www or public_html.

How is the .htaccess file used?

Common uses include redirecting URLs, display customized error page [404s], enable password protection, and enhance SEO via consistent trailing slash practice.

How to create the default .htaccess file in WordPress?

Use a text editor to create default .htaccess file and upload it on your server via FTP. For more details, you can visit the AliveBetter blog.

You can create .htaccess file thorugh cPanel under ‘public_html’ directory. Example of default WP .htaccess code is –

# BEGIN WordPress

  1. <IfModule mod_rewrite.c>
  2. RewriteEngine On
  3. RewriteBase /
  4. RewriteRule ^index\.php$ – [L]
  5. RewriteCond %{REQUEST_FILENAME} !-f
  6. RewriteCond %{REQUEST_FILENAME} !-d
  7. RewriteRule . /index.php [L]
  8. </IfModule>

# END WordPress

Now, save and close. Visit your WP website to make sure that the new .htaccess files works properly. If it is incorrect, a 500 internal error page gets triggered.

Why isn’t the .htaccess file visible?

Filenames starting with a dot [.] means hidden files. You cannot directly see them in default settings. This does not mean you cannot gain access to the .htaccess file. File Manager has a setting like ‘show hidden files’. On other programs, it can be accessed via ‘preferences’, ‘folder options’, ‘settings’ or in ‘view’ menu.

What are the benefits of the .htaccess file?

  • Redirects
  • Custom error pages
  • Authentication
  • SSI
  • Mod_ Rewrite
  • Enabling CORS
  • Leverage browser caching
  • Restrict or allow users by domain
  • Hotlink protection

What are the drawbacks of the .htaccess file?

  • Speed – Sometimes the page’s portal location can affect its directory and sub-directories. This can impact the website speed. If you have access to the httpd.conf.file, which allows configuration for the entire server.
  • Security – Individual users can add or enhance or configure the server-side coding rules. This can create a security gap if the editing is not handled properly.

Troubleshooting tips

If you mess with .htaccess file incorrectly, it can seize the server and cause 500 internal server errors. Few troubleshooting tips to help you are –

  1. Perform one thing and test….if it works then move to the next and test it….! If several things get done simultaneously and it fails, you will not know which command was responsible for the issue.
  2. Save every command that worked before moving to the next. There is no UNDO option, so backup files before every command. It helps to restore the working version in case there is a mess!
  3. If you are finding it hard to identify the issue then check Apache error logs. You can find valuable detail on where to look.
  4. Sometimes common issues like .htaccess disabled or filename without a dot or there is an overridden directive. These are easily fixable!

Author: admin

Leave a Reply

Your email address will not be published. Required fields are marked *