Apache — How To Set Up .htaccess File | What is Apache [ Fully Guide]

TechnoGyanBaba
4 min readSep 19, 2020

The .htaccess file running on Apache makes a powerful tool to allow you to modify your Apache configuration at the directory and subdirectory level. htaccess File on Apache make cancellation the Apache global and virtual host settings. By this htaccess, you can alter your website’s configuration without changing server configuration files.

A configuration file, a distributed server configuration file, used on the web servers which are running on the Apache Web Server software. A .htaccess (hypertext access) is used to change the configuration of the Apache Web Server software. Then By this htaccess file, you will be able to adjust server configurations for a specific directory.

  • It supports several web servers.
  • It solves the issues of website-access related to configuration like access control, URL redirection, URL shortening.
  • .htaccess file, a plain-text configuration file, uses the same syntax as the main configuration file uses.
  • .htaccess file makes configuration changes to your server.
  • Any directive for better set in a Directory block, htaccess files retard Apache http server to include directive in a .htaccess file for better performance.
  • As htaccess files are reliable and authentic, they make your website less desirable to hack.
  • These files normally can not be obtained easily as they are in the http file of the server having the rule to deny access to htaccess files.
  • .htaccess is the non-alternative and unique file for per-directory Apache config file.

.htaccess file to be used by the user who is using shared hosting. The user of shared hosting likely need to use the .htaccess file. When you are using a virtual private server or a dedicated server, then you have to access the main server configuration file, htaccess file.

You can get .htaccess file in the website’s folder of public_html.

If you want to set server configurations for a specific directory. This .htaccess file is used on the Apache webserver. It is used on some web servers also. This specific directory may be the root directory for your website.

By breaking it deliberately, edit the. htaccess file. Apache programming language is used to write htaccess files.

Apache is HTTP Server, a free and open-source cross-platform, Apache webserver software, issued under Apache License 2.0. It maintains a community of developers under Apache Software Foundation. Nginx is considered as the best alternative to Apache. Only on this basis that Nginx is lighter having a better option for the lower-specs server. Apache server controls all requests with high-priced overhead, despite Nginx, for knowing about this, assist the static resources without PHP.

Set up a connection between a server and the browsers website visitors. It is a cross-platform software, multi-platform software, platform-independent software. It may run on Linux, macOS and Microsoft Windows.

By default .htaccess File is disabled

  • So in first, you are to enable Apache .htaccess by opening the default host configuration file.
  • So In this section, change the
  • AllowOverride None entry to all: To AllowOverride All
  • Then Save the file and after then restart the Apache service.
  • sudo service apache2 restart
  • For stopping viewing the directory and file structure, change default settings so that none can access to files on the webserver.
  • So you have to create .htaccess File
  • Open the .htaccess file entering:
  • sudo nano /var/www/my_website.com/.htaccess
  • Next, so you have to restrict IPsPermalink
    so that you can restrict particular IPs to access your website.
    This is useful if you want to block certain visitors from visiting your site. You may also set this up to prevent certain IPs from accessing certain sections of your site.
  • You can give permission a few IP addresses blocking the rest.
  • Move into the commands:
  • order deny, allow
  • allow from 192.168.0.54
  • allow from 192.168.0
  • For Blocking IP Addresses, after then enter the commands:
  • order allow, deny
  • For blocking a single IP address, then enter the command:
  • deny from 192.168.0.54
  • For Redirecting Traffic, open the .htaccess file and then move into the commands:
  • Redirect301/Other_Website.com/index.html/My_Website.com/index.html
  • For setting a 404 Page
  • By using .htaccess on Apache, so you can customize to display any other error page you would like when a user tries to access an inexistent page.
  • For 404 page, a new location, open the .htaccess file and then move into the commands:
  • ErrorDocument 404 /404.html
  • For creating the 404 page, enter the words:
  • sudo nano cd /var/www/My_Website.com/public.html/404.html
  • Further, plus the next code:
  • <!doctype html> <html> <body> 404 Error: Page not found </body&gt; </html>

(web server = server software) That satisfy client’s requests on World Wide Web It contains one or more websites. Every HTTP request will get an answer by the web server.
After receiving the request, an HTTP server starts to examine the requested URL is matching the current file or not.

An HTTP server, web server software, that is free and open-source cross-platform. Incoming requests of processing and answering are completed by the HTTP server.

I have described in details, how to set up the htaccess file on Apache? What is htaccess file and why you have to set up the htaccess file? How to find out and where is the .htaccess file? Who needs .htaccess file, What is the uses? What is Apache, HTTP server and the webserver.

Originally published at https://techlearneasy.com on September 19, 2020.

--

--