How to Convert .htaccess Rules to NGINX Directives

October 2, 2020 Liquid Web

NGINX is a web server that is becoming an increasingly popular option for web hosting, as sixteen percent of all sites on the Internet are utilizing NGINX. This percentage is constantly increasing as clients require a web server that can serve content faster. It can also be used for proxies, reverse proxies, load balancing, and more, depending on what modules you load onto NGINX. One of the significant differences between Apache (a popular webserver) and NGINX is the way each system handles access rules. If you are familiar with using .htaccess rules in Apache, then the method that NGINX uses of including directives in the server’s vhost block will be a substantial change.

In this video, we demonstrate how to convert .htaccess rules to NGINX directives.

Commands used:
rewrite regex URL [flag];

RewriteCond %{HTTP_HOST} example.com
RewriteRule (.*)https://www.example.com$1

nginx -t
nginx -s reload

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Video by: Justin Palmer

About the Author

Liquid Web

Liquid Web powers online content, commerce, and potential for SMB entrepreneurs and the designers, developers and digital agencies who create for them. Sign up for our <a href="https://www.liquidweb.com/blog">newsletter</a> to stay up to date with our latest content.

More Content by Liquid Web
Previous Video
Locations of Common Log Files on cPanel Servers
Locations of Common Log Files on cPanel Servers

One of the nice things about cPanel servers is the way that they keep the location of key files in the same...

Next Video
How to Install Squid Proxy Server on Ubuntu 16.04
How to Install Squid Proxy Server on Ubuntu 16.04

In this video, we demonstrate how to install and configure a Squid Proxy server on Ubuntu 16.04.

Learn What Qualities to Look for in Your Next Host in Our New Guide!

Download Now