This is a hidden plain-text file, an optional tool that you can incorporate into the directories of websites hosted on Apache servers. This file, called .htaccess, opens up a world of advanced functions: from redirecting traffic from www to non-www, to customizing 404 errors, blocking malicious bots, or managing permanent (301) and temporary (302) redirects. It even allows you to (? Blocking web access via .htaccess) and protect your website against unwanted access—all with just one file!
💡 On Linux operating systems, hidden files begin with a period (e.g., .htaccess). SWPanel(? File management) allows you to view these files, but they may be hidden in other file managers. In Filezilla, go to the Server section and select Force Show Hidden Files; in bash, you can use the
ls -lacommand to view hidden content. This way, you’ll always have everything under control.
Our Hosting gives you the freedom to tailor your website to your brand and goals.
Generally, the .htaccess file is located in the root directory of your hosting, and in SW Hosting, this directory is /web. If you can’t find the file, you can create one yourself. Use a text editor such as Notepad, add the necessary code, and upload it to your hosting (? How to access your Hosting service using Filezilla), ensuring you name it ".htaccess" (including the initial period). That’s it!
The .htaccess file is a hidden file precisely to protect it from prying eyes. It’s not accessible to the public or anyone attempting to view it directly through a URL, such as https://swhosting.com/htaccess. You can be sure that only you have access to its content!
The .htaccess file consists of directives (instructions) that tell the server how to respond to requests. Each directive starts with a command and may include one or more arguments. Apache reviews the file each time a resource in a specific directory is requested, executing the relevant directives. For instance, to redirect all requests fromhttp://www.swhosting.com/es to https://www.swhosting.com/es, you could add the following code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Or, if you want a 301 redirect (permanently redirecting from old.html to https://www.swhosting.com/nueva-pagina):
RewriteEngine On
RewriteRule ^old\\.html$ https://www.swhosting.com/nueva-pagina [R=301,L]
Despite its versatility, .htaccess is not designed for global changes on the server. Additionally, incorrect configuration or syntax can cause 500 errors or make your website inaccessible. It is advisable to create a backup of any .htaccess file before making changes and to test each modification to ensure functionality.
The .htaccess file is an essential tool for those looking to customize and optimize their website to the fullest. From redirects to advanced security and performance configurations, this file gives you total control over many aspects of your site. Remember that incorrect usage can affect its functionality, so always make backups and refer to Apache documentation to make the most of its possibilities. At SW Hosting, we provide the perfect environment for you to explore all the advanced functions .htaccess can offer.
Our Hosting gives you the freedom to tailor your website to your brand and goals.