Welcome ðŸŽ‰

logo

ReactLMS

Search
Light Mode
Contact Us

4 min to read

Contact us

No results for your search.
Sorry, an unexpected error occurred

Introduction


This is an effective way of website navigation, through this method, we can use a domain to represent or substitute for another domain or address.


Redirects


Redirects, also known as navigation, is the way we often use to redirect users to another website when accessing a specific URL.

Refer to the following example

events {
}

http {
    include /etc/nginx/mime.types;
    server {
        listen 80;
        server_name nglearns.test;
        root /srv/nglearns/static-demo;
        location = /index_page {
          return 307 /index.html;
        }
        location = /about_page {
          return 307 /about.html;
        }
    }
}






Run the following command

curl -I http://nglearns.test/about_page






Result

# HTTP/1.1 307 Temporary Redirect
# Server: nginx/1.18.0 (Ubuntu)
# Date: Thu, 22 Apr 2021 18:02:04 GMT
# Content-Type: text/html
# Content-Length: 180
# Location: http://nginx-handbook.test/about.html
# Connection: keep-alive






Through the example above, Now when we access with the path http://nglearns.test/about_page We will be redirected to http://nglearns.test/about.html


Rewrite


Similar to redirects, rewrite allows us to access another source but it does not change the current URL

Refer to the following example

events {
}

http {
    include /etc/nginx/mime.types;
    server {
        listen 80;
        server_name nglearns.test;
        root /srv/nglearns/static-demo;
        rewrite /index_page /index.html;
        rewrite /about_page /about.html;
    }
}






Experiment with the following url

curl -i http://nglearns.test/about_page






Result

# HTTP/1.1 200 OK
# Server: nginx/1.18.0 (Ubuntu)
# Date: Thu, 22 Apr 2021 18:09:31 GMT
# Content-Type: text/html
# Content-Length: 960
# Last-Modified: Wed, 21 Apr 2021 11:27:06 GMT
# Connection: keep-alive
# ETag: "60800c0a-3c0"
# Accept-Ranges: bytes






Through the example above, we can see that when accessing http://nglearns.test/about_page, you will be able to access the about.html file

🌱
Using rewrite will enhance the user experience because it does not change the URL during the access process



Read more
On This Page