How to connect to databa<x>se using NaviCat MySQL client
Table of the most frequent errors in FTP clients
What permissions should be used for uploading files?
Install Apache and PHP on CentOS 7
How to Connect to a Remote Server via SSH from Windows Linux or Mac
What virtualization technology is set up on VPS?
Proxmox vs. Hyper-V: How to Choose?
21 Server Security Tips to Secure Your Server
What is the difference between Shared Hosting and Dedicated server
Resetting Dedicated server root password via Virtual Console
IIS 10: Moving an SSL Certificate to Another Server
Installing an SSL certificate on Apache
Installing an SSL Certificate on IIS 7
HTTP to HTTPS redirection on IIS
The difference between SSL and TLS
What Is a Broadcast IP Address?
How can I see and change the geolocation information about an IPv4 address block?
How do I know that the IPv4 addresses are clean and not on any blacklists?
2024-03-07 07:53:58
You use a redirect whenever a website owner wants an address to reroute to
another address, typically redirecting HTTP to HTTPS
or redirecting one domain to another domain.
HTTP to HTTPS scenario:
You want your customers to reach your secure (SSL) site even if they type
in http://yourwebsite.com
or yourwebsite.com
into their browser. This type of
redirect accomplishes just that. For example, if your customer types in http://yourwebsite.com
,
the redirect in Nginx® redirects the request to https://yourwebsite.com.
One domain to another scenario:
You own yourwebsite.com, yourwebsite.org, and yourwebsite.net, and
you want your customers to arrive at yourwebsite.com regardless of the URL they enter
into their browser to visit your site.
The following sections describe how to redirect from HTTP to HTTPS and from one
domain to another domain.
When you install an SSL certificate on your server, you have two
server blocks for your website: one each for HTTP and HTTPS. The problem is
you need a way to force traffic to your SSL-secured site (the HTTPS version).
You can accomplish this by adding a redirect to the Nginx server block for your
website.
Open the configuration file for your domain. The file should be named similar to
/etc/nginx/vhost.d/yourwebsite.com.conf. The .conf indicates
the configuration file for your domain. Open the file with your favorite text editor.
The following example uses the vim
editor:
Shell
Depending on your particular configuration, this might contain more
information than the preceding example, but this is a
simple example focusing on the redirect option.
However, you want your customers to go to the secured version of
yourwebsite.com, so you need to add a redirect to the server block
in the configuration file. To do that, modify the block to look similar
to the following example and save the file:
Shell
With the preceding redirect line in place, any time your customers type in
yourwebsite.com or www.yourwebsite.com, the system automatically
redirects them to the https://yourwebsite.com version of your website.
Note, however, that you must add this line to the HTTP 80
server block, not
the HTTPS 443
server block.
You should probably also redirect any https://www.yourwebsite.com
requests to https://yourwebsite.com. You can do this by adding another
redirect line to the 443
server block, often located below the 80
server
block in the configuration file. That change looks similar to the following example:
Shell
Note: Your server blocks likely contain more information than the
preceding simplified examples.
When you have a domain with multiple top-level domains (such as .com,
.net, .org, and so on) and want all of those sites to reach the
same website, use a redirect. For this example, we assume that you own
yourwebsite.com, yourwebsite.org, and yourwebsite.net, and you want
to redirect all of those to yourwebsite.com.
Edit the configuration file for your domain again. Instead of adding
an HTTPS redirect, modify the server block as shown in the following
example:
Shell
Now, whenever your customers enter yourwebsite.net or yourwebsite.org, the
system redirects them to yourwebsite.com instead.
Save and close your configuration files after your edits and restart both nginx
andphp-fpm
to make those changes go live.