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:
- 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 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…
- 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)…
- Deploy Stand Alone Vue Nginx Deploy Stand Alone Vue Nginx What is Vue.js? Vue.js is an open source JavaScript framework for building user interfaces. It was created by ex-Google employee, Evan You, and is now…
- Where Is Nginx Document Root Where Is Nginx Document Root What Is Nginx? Nginx is an open source, high-performance web server and reverse proxy software popular on Linux and Unix. It is used to serve…
- Install Nginx Php Windows 7 Install Nginx Php Windows 7 What is Nginx and PHP? Nginx and PHP both are web server applications that are used to host websites on the internet. Nginx is an…
- 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…
- Reverse Proxies Nginx Centos 6 Reverse Proxies Nginx Centos 6 What is a Reverse Proxy? A reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or…
- 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…
- 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…
- 500 Internal Server Error Nginx Angular 500 Internal Server Error Nginx Angular What Are the Causes of 500 Internal Server Error Nginx Angular? One of the most frustrating, yet common, errors you may run into with…
- 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…
- Cache Fast Cgi On Server Not Browser Nginx Cache Fast CGI On Server Not Browser Nginx What is Fast CGI? FastCGI is an open source protocol created to allow web applications to run on external web servers. It…
- Nginx Session For Web Configure Nginx Session For Web Configure What is Nginx Session? Nginx session is a solid-state storage and authentication mechanism which enables web servers to execute multiple web requests in protected environment.…
- Change Html Folder To Www Nginx Change Html Folder To Www Nginx Introduction As websites continue to grow in size and complexity, it has become increasingly important to be able to customize and tweak the hosting…
- 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…
- 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…
- Nginx Program Delete Cant Running With Extension Nginx Program Delete Cant Running With Extension What is Nginx? Nginx is an open-source, powerful web server that is designed to serve static content quickly and efficiently. It is well…
- Nginx Proxy_Cache_Bypass Cookie Nginx Proxy_Cache_Bypass Cookie What is a Proxy_Cache_Bypass Cookie? A Proxy_Cache_Bypass Cookie is a special kind of cookie used to instruct a proxy server to bypass its own caching process. This…
- What Is The Difference Between Uwsgi And Nginx What Is The Difference Between Uwsgi And Nginx? What Is Uwsgi? Uwsgi stands for “Unicorn web server gateway interface”. It is a powerful, highly configurable and widely used web server…
- 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…
- Nginx Php-Fpm Different Servers Nginx Php-Fpm Different Servers What is Nginx? Nginx is an open source web server developed by Igor Sysoev in 2004. It is a web server used to deliver web content…
- Web Server Nginx Walid Umar Web Server Nginx Walid Umar Introduction to Nginx web server Nginx is an open source web server developed by Russian software engineer Igor Sysoev. The Nginx project is sponsored by…
- Reverse Proxy Varnish Vs Nginx Reverse Proxy Varnish Vs Nginx What is Varnish? Varnish is a web accelerator and a reverse proxy program that runs on dedicated hardware and acts as a front end for…
- Laravel Migration From Apche To Nginx Laravel Migration From Apache To Nginx What is Nginx? Nginx is a web server that has become increasingly popular over the years. It is robust, reliable, and secure. Nginx is…
- 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…
- 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.…
- An Internal Server Error Occurred Nginx An Internal Server Error Occurred Nginx What is an Internal Server Error? An internal server error is a general term used to describe an error that occurs on a web…
- 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.…