What is the .htaccess file? Print

  • 0

We will go over this one a bit later on. As an outline, the hypertext access file is a configuration file used by several web servers. It handles URL redirection, URL shortening, access control and much more.

We don’t need to go too in depth with this, just remember that it important for how the browser displays the URL for your web page. Also the ‘dot’ before the file name makes it a hidden file, we will reveal hidden files so don’t worry about this.

 

Accessing Your Files

If you try to access any html file now, you will find that the browser displays the url with the file extension. e.g. “example.com/test.html”… I don’t like this so here is what I do to fix it or get a cleaner URL “example.com/test”;

As a note, I use index.html for the file I want the browser to read first when I access the folder. I believe this is industry standard.

for every folder with a html page the browser will display, create a new file called “.htaccess”. In the file I use the following code. As I described above, it tells the browser to display the page URL in a specific way.

Right click the new .htaccess file and click edit. The character encoding should be set to “uft-8”. Leave it and click edit.

Paste the following code and click save then close.

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]

RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+).html [NC]
RewriteRule ^ /%1 [NC,L,R]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
          

Was this answer helpful?

« Back

Powered by WHMCompleteSolution