Disclaimer – This article is for informational purposes only. The author does not make any representations or warranties as to accuracy, completeness, or the results obtained from any information provided.
Hide HTML Extension On Nginx
What is Nginx?
Nginx is an open-source server software that is used to offer web services. It is a popular choice among developers due to its high performance, scalability, low-resource usage, and stability. Nginx is a reverse proxy, meaning it acts as a proxy server, transferring requests from clients to other web servers. Nginx can be used for hosting static websites as well as dynamic websites. It can also be used for caching and load balancing.
Why Hide HTML extension?
The web pages created with HTML have an extension of ‘.html’ as a default. When visitors visit your website, the URL shows the full file extension in the address bar. If you want to have a short URL, then hiding the file extension will help you to do it. It will make the address of the website easier to remember and type. Moreover, it is beneficial from the SEO point of view, as search engines prefer short URLs.
How to Hide HTML Extension on Nginx with ReWrite Module?
To hide the HTML extension on Nginx, you need to enable the rewrite module by typing in the following command:
nginx -t
Once the rewrite module is enabled, create a file with the name of “.htaccess” in the root directory of the Nginx server and copy the following code into it:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
This will enable you to hide the HTML extension for all the web pages on the website. It is important to note that this code will rewrite all the URLs on the website, which is why it is not recommended to use on websites with hundreds of pages or a large amount of traffic.
How to Hide HTML Extension Using Nginx Config?
If you want to hide HTML extensions for only a few webpages, then it is better to use the Nginx config file. To do this, open the Nginx config file and add the following snippet given below:
location /somepage {
rewrite ^/somepage$ /somepage.html last;
}
The above snippet will rewrite the requested URL ‘somepage’ to ‘somepage.html’ and render the HTML content for the webpage. It will also hide the HTML extension from the address bar. This method is more efficient as it only applies to the webpage specified and not to the entire website.
Other Ways to Hide HTML Extenison?
Apart from using the ReWrite module or Nginx config file to hide the HTML extension, there is also another way to do it, which is to use mod_rewrite module in Apache. This module can be enabled to hide the HTML extension for all the webpages of the website. To enable it, open the Apache configuration file and add the following code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.html [NC,L]
Once the code is added to the Apache configuration file, the module will be enabled on the server and the HTML extensions will be hidden from all requesters.
Conclusion
Hiding HTML extensions on Nginx is a simple process. You can either use the ReWrite module or Nginx config file. By hiding the HTML extension, you can make the URL of the website shorter and easier to remember. It is also beneficial from the SEO point of view, as most search engines prefer short URLs. Moreover, it also adds a level of security as the file extension will be hidden from visitors.
FAQs
- What is Nginx?
Nginx is an open-source server software that is used to offer web services.
- How to hide HTML extension on Nginx?
To hide the HTML extension on Nginx, you need to enable the rewrite module, create a file with the name “.htaccess” in the root directory and add the code given in the article.
- What is the purpose of hiding HTML extension?
Hiding the HTML extensions helps in making the URL shorter and easier to remember. It also helps in improving the SEO ranking of the website.
Thank you for reading this article. Please read other articles by clicking the keyword ‘Hide HTML Extension on Nginx’ to learn more about Nginx.
Related Posts:
- Nginx Config Proxy Pass Using Https Nginx Config Proxy Pass Using Https Introduction Nginx is an open source web server that contains robust and efficient config proxy pass feature for its users. It is designed to…
- Nginx Tcp Multiple Port Forwarding Nginx Tcp Multiple Port Forwarding What is TCP Port Forwarding? TCP port forwarding is a network action that enables a computer to redirect communications that are normally sent over the…
- Install Database Mysql Vagrant Nginx Install Database Mysql Vagrant Nginx What is Nginx? Nginx is an open source, high-performance web and proxy server designed to serve a variety of web applications. It handles requests from…
- Index.Htm On Nginx.Conf Index.Htm On Nginx.Conf Introducing Nginx.Conf Nginx.Conf is a configuration file for the Nginx web server software, developed by Russian open-source software developer Igor Sysoev. Nginx.Conf contains directives (configuration commands) for…
- Nginx Config Server Proxy_Pass Nginx Config Server Proxy_Pass What is Nginx and How Does it Work? Nginx is an open source web server and reverse proxy used to host websites and distribute traffic across…
- How To Count Nginx Scalability How To Count Nginx Scalability What is Nginx? Nginx is an open source web server and reverse proxy server developed by Igor Sysoev. It is a high performance web server…
- How Use Nginx Mysql Ubuntu How to Use Nginx, MySQL and Ubuntu What is Nginx? Nginx is an open source web server and reverse proxy software written by Igor Sysoev. It is a popular choice…
- Nginx Multiple Web Sites One Ip Nginx Multiple Web Sites One Ip Introduction Nginx is a powerful and popular web server used by millions of websites and web application around the world. It is highly performant,…
- Nginx 1.10.3 Vs 1.3.0 Nginx 1.10.3 Vs 1.3.0 Overview of Nginx Nginx is a web server software package developed to run high-performance web applications and services. It is one of the most popular web…
- Install Nginx On Centos 6 Install Nginx on CentOS 6 What is Nginx? Nginx is a web server and a reverse proxy server for HTTP, HTTPS, SMTP, POP3 and IMAP protocols, with a strong focus…
- Nginx Reverse Proxy Pass Hostname Nginx Reverse Proxy Pass Hostname What is Nginx Reverse Proxy Pass? Nginx reverse proxy pass is an Nginx option that can be used to specify the host name of an…
- Raspbian Install Nginx And Php7 Raspbian Install Nginx And Php7 Introduction to Nginx and PHP Nginx is a powerful open source webserver and reverse proxy solution. Nginx is lightweight and fast, enabling webmasters to serve…
- 403 Forbidden Nginx Docker Lumen 403 Forbidden Nginx Docker Lumen What is 403 Forbidden Error? A 403 Forbidden error is an HTTP status code that means that accessing the page or resource you were trying…
- Ubuntu Server18 How To Enable Nginx Pdo Mysql Ubuntu Server18: How to Enable Nginx Pdo Mysql As a developer, you may have heard of Nginx, PDO, and MySQL – all are essential components of web applications. Nginx is…
- Nginx Php Fpm 7.2 Nginx Php Fpm 7.2 Introduction to Nginx and PHP-FPM Nginx is an open-source web server, reverse proxy server, and load balancer. It is known for being lightweight and fast, and…
- Multi Host In Nginx Debian 9 Multi Host In Nginx Debian 9 Introduction Nginx is a web server that can be used for hosting multiple websites on a single server. This guide will help you set…
- Install Letsencrypt Debian 9 Nginx Install Letsencrypt Debian 9 Nginx What is Letsencrypt? Letsencrypt is an open source, free, automated SSL service that provides users with the ability to secure their websites and use HTTPS…
- What Is Reverse Proxy Nginx What Is Reverse Proxy Nginx? What is Nginx? Nginx is a free, open-source web server software developed by Igor Sysoev since 2002. It gained immense popularity due to its ability…
- Enable Php Intl In Nginx Enable Php Intl In Nginx What is Php Intl? First thing we should discuss is what is Php Intl. PHP Internationalization or Intl is a set of PHP extensions providing…
- How To Know Apache Or Nginx How To Know Apache Or Nginx Understanding Apache and Nginx Apache and Nginx are two of the most popular web servers used today. Apache is a open-source web server management…
- Deploy Laravel In Local Nginx Windows Deploy Laravel In Local Nginx Windows 1. Introduction To Nginx Nginx is a web server that is primarily used to handle web traffic. It is open source, meaning it is…
- No Max-Age Or Expires Nginx No Max-Age Or Expires Nginx What is an Nginx Server? Nginx is an high-performance web server that is designed for serving static and dynamic content quickly. Nginx is currently used…
- Nginx Reverse Proxy Connection Refused Nginx Reverse Proxy Connection Refused What is Nginx? Nginx is a powerful web server and reverse proxy server with a wide range of features and applications. Nginx allows you to…
- Ubuntu 18.04 Nginx Hide Port Ubuntu 18.04 Nginx Hide Port Introduction to Nginx with Ubuntu Nginx is an open source web server and reverse proxy software that is commonly used in Linux servers. It is…
- Mime Font Ttf Nginx Gzip Mime Font Ttf Nginx Gzip What is Mime Font Ttf? MIME font ttf is a type of TrueType Font format designed for web developers. It is used to display text…
- Vps Webserver Nginx Php7 Mysql Vps Webserver Nginx Php7 Mysql What Is VPS Webserver? A VPS webserver is a Virtual Private Server (VPS) that has been configured to act as a web server. A VPS…
- Odoo Nginx Reverse Proxy Docker Odoo Nginx Reverse Proxy Docker What is Odoo? Odoo, formerly known as OpenERP and TinyERP, is an open-source Enterprise Resource Planning (ERP) software that helps businesses with their core processes…
- Upstream Timed Out Laragon Nginx Stackoverflow Upstream Timed Out Laragon Nginx Stackoverflow What is Nginx? Nginx is a popular open-source web server, known for its high performance, low resource usage, and scalability. It is usually used…
- Nginx More Than 4 Config Nginx More Than 4 Config Basics of Nginx Nginx is a powerful, open source web server. It is designed to be both efficient and secure. It is used to animate…
- Mac Os X Nginx Conf Location Mac OS X Nginx Conf Location What is Nginx? Nginx is a high-performance web server and reverse proxy originally written for Linux, but now it’s also available for Mac OS…