Click on the banner to learn about and purchase my database training on Azure

Utilities of the .htaccess file

Views: 2.542 views
Reading Time: 4 minutes

Hello people,
Good Morning!

In this post, I will share useful information related to the .htaccess file, which is the Apache HTTP server configuration file, in which I have already made some posts about on this link. These tips I found on the blog and I found the content excellent and decided to share with you these little precious tips.

To create the rules below, open notepad or similar, save as “all files” and named .htaccess. It is worth mentioning that some codes will only work if certain extensions are enabled in Apache. If any code generates a 500 error, enable the corresponding module in apache. And to avoid such errors, make the codes in conditional structures ( ), so the code will only be executed if the module is active.

Hiding URL Indexing

Protecting your site from copying or misusing files (such as php, js, css, images)

Block .htaccess file from URL access

Blocking specific files against URL access

Set default file upload order

By default, the file to upload when you type the website URL and open a web page is index.html. However, this can be easily changed as needed by changing the server .htaccess file.

Using the code below, we set the default page to be index.php. If this file does not exist, the next file in the list (index.htm) will be loaded and so on until it reaches the last file in the list (page.php). If this last file does not exist, apache will reproduce an error in your site's visitor browser (Error 403 - Forbidden).

Increase PHP session time

Always put “www” in the URL

Compress site files to consume less bandwidth

Enabling compression with DEFLATE

This is the easiest compression to configure on the server and is already enabled by default. It uses less server processing than GZip, but does not compress as much as it does.

Enabling Compression with GZip

GZip has been gaining a lot of space on the web today because of its great data compression power, reducing page load times dramatically, especially when we talk about mobile internet (3G) in Brazil, which is still very slow and precarious Many places. Because it has a high level of compression, it requires more processing than the DEFLATE compression method.

Creating custom error pages

Change website homepage (default)

Block directory listing

Force SSL Usage

Disable case sensitive

Restricting IP Access

Redirect access from one site to another place

Regular expressions

Remove extensions from URL

Force use of UTF-8 Charset for files

Browser Cache - Set Expiration Time (seconds)

Browser Cache - Set Cache Control (Seconds)

Browser caching - Force caching by disabling ETag

Add new mimetypes

Disable Execution of Certain Scripts

Change the default language

Change default time zone

Force download certain files

Block request based on user-agent

That's it folks!
I hope you enjoyed this post and see you next time.