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:
- Kubernetes Ingress Nginx Http Header Kubernetes Ingress Nginx Http Header What is Ingress Nginx? Ingress Nginx is a powerful and flexible open source web server and proxy server software. It's a popular choice for Kubernetes…
- 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…
- Laradock Nginx Exit Duplicate Default Server For… Laradock Nginx Exit Duplicate Default Server For 0.0.0.0:80 In What is Nginx Derived From? Nginx is derived from an open-source and high-performance HTTP server developed by Russian developer Igor Sysoev.…
- Run Service Nginx Automatically Docker Run Service Nginx Automatically Docker What is Docker? Docker is an open source and lightweight containerization platform designed with developers in mind. It is based on a "container" technology, which…
- Nginx Sites Availeble Digital Ocean Nginx Sites Available Digital Ocean What is a Nginx Site? In the world of hosting providers, Nginx (pronounced “engine x”) is one of the popular choices to host your website.…
- Nginx Not Read Index.Php Nginx Not Read Index.Php What is Nginx? Nginx is an open source web server software that is used to serve webpages. It was originally written to handle heavy loads of…
- Install Nginx And Php Scract In Docker Install Nginx And PHP Script in Docker What is Docker? Docker is a popular platform for creating, running, and managing applications in a lightweight container system. Originally released as an…
- Compare Webproxy Nginx And Apache Compare webproxy Nginx and Apache What is Nginx? Nginx (pronounced “engine-x”) is a web server that is used for web-hosting purposes. It is open source software that is available for…
- Setting Permalink Seo Friendly Nginx Error 404 Setting Permalink Seo Friendly Nginx Error 404 What is Nginx? Nginx (pronounced "engine x") is a popular and open-source web and reverse proxy server. It is becoming increasingly popular in…
- How To Set Static Nginx How To Set Static Nginx Understanding What is Nginx? Nginx is an open source Web server software used for hosting static or dynamic websites, media streaming, and other web applications.…
- Linux How To Stop Nginx Linux How To Stop Nginx What is Nginx? Nginx is a free, open-source web server and reverse proxy software. It was designed to be a highly scalable, reliable, and high-performance…
- Digital Ocean Ubuntu Server Nginx Docker Digital Ocean Ubuntu Server Nginx Docker Understanding Digital Ocean Digital Ocean is a cloud service provider that focuses on simplifying web infrastructure for cloud developers. They offer a platform where…
- Can I Use Nginx For Cpanel Can I Use Nginx For Cpanel? What is Nginx and What Does it Do for Cpanel? Nginx is an open source web server and reverse proxy created by Igor Sysoev…
- Nginx Reverse Proxy Subdirectory Laravel Nginx Reverse Proxy Subdirectory Laravel What is Nginx? Nginx is a popular open-source web server used for running web applications. It is fast and can handle large amounts of traffic.…
- Nginx Change Default Index.Html Nginx Change Default Index.Html What is Nginx? Nginx is a popular open source web server and proxy server that powers some of the world's busiest websites. It is primarily used…
- Codeigniter 404 Not Found Nginx Reverse Proxy Codeigniter 404 Not Found Nginx Reverse Proxy What is CodeIgniter? CodeIgniter is an open-source software development framework used for developing web applications written in PHP. The primary goal of CodeIgniter…
- Nginx Conf Load Balancer Example Nginx Conf Load Balancer Example What is Nginx Conf Load Balancer? Nginx Conf Load Balancer is an open source web server and a reverse proxy server that facilitates the process…
- Nginx Adding Html Add_Before_Body Nginx Adding Html Add_Before_Body Understanding Add_Before_Body Directive Nginx is a web server that is widely used to serve dynamic web content such as websites and applications. The Add_Before_Body directive is…
- Nginx Proxy To Port 8080 Nginx Proxy To Port 8080 What is Nginx? Nginx is an open-source, high-performance web server developed in 2002 by Igor Sysoev and released publicly in 2004. It is a very…
- Nginx Reverse Proxy Node Js < h1 > Nginx Reverse Proxy Node.js < h2 > What is Nginx Reverse Proxy? < p > A reverse proxy is a type of proxy server that takes HTTP(S)…
- How To Hide Nginx In Centos 7 How To Hide Nginx In Centos 7 What is Nginx? Nginx is a powerful web server and is one of the most popular web server software available today. It's a…
- Hide Nginx Version Header All Path Hide Nginx Version Header All Path What is Nginx ? Nginx (pronounced Engine X), is an open source, cross-platform web server software that can be used to handle the requests…
- Nginx Access To Xmlhttprequest At Nginx Access To Xmlhttprequest At What is Nginx? Nginx is an open source web server and proxy server software that is designed for both high-performance web applications and for scalability.…
- Googlec Cloud Hosting Nginx Caching Proxy Google Cloud Hosting Nginx Caching Proxy What is Nginx? Nginx is an open source web server typically used to serve high-traffic websites. It offers a powerful set of features and…
- 404 Not Found Angular Nginx 404 Not Found Angular Nginx What is a 404 Not Found Error? A 404 Not Found Error is an HTTP status code that means that the page you were trying…
- Available Application Apache And Nginx Available Application Apache And Nginx What is Apache? Apache is a web server software that allows users to store and deliver web content quickly and efficiently. Apache was created in…
- Reverse Proxy Nginx Dan Windows Server Reverse Proxy Nginx Dan Windows Server Introduction to Reverse Proxy Reverse proxy is a server that is used to receive requests from the Internet and forward them to other servers.…
- How To Know If Nginx Is Working For A Directory How To Know If Nginx Is Working For A Directory Nginx is a popular open-source web server that is widely used in many websites and applications. It is known for…
- Reverse Proxy Nginx Php Node Js As Same Port Reverse Proxy Nginx Php Node Js As Same Port What is Reverse Proxy? Reverse proxies are a type of software which allows a system to make an indirect connection between…
- Nginx Reverse Proxy Upstream Ssl Nginx Reverse Proxy Upstream Ssl What is Nginx Reverse Proxy? Nginx reverse proxy is a technique used to provide internet users with the ability to access services on a variety…