How to set and customise redirect?

No .htaccess file is allowed on the server because of using Nginx for a web server on our AMI.

Two ways to redirect access

  1. Use WordPress plugin (easy)
  2. Modifying /etc/nginx/conf.d/example.conf to set up redirect

 

Use WordPress plugin (easy)

You can use any WordPress plugins for redirecting access. For example,

Easy to set up.

  1. Install and activate;
  2. Input Source URL which means redirect from;
  3. Input Target URL which means redirect to;
  4. Save changes
  5. Try and check your redirections are works correctly.

These plugins have import and export feature; you can set many redirects at once. If you want to use a regular expression, Redirection plugin has it as its feature.

 

 

Modifying /etc/nginx/conf.d/example.conf to set up redirect

Here is some example.

Redirect example.com to www.example.com

Add following block after include /etc/nginx/drop; block.

location / {
        return 301 http://www.example.com$request_uri;
    }
	

Like this:

$ sudo su -
# vi etc/nginx/conf.d/example.com.conf

server {
    listen      80;
    server_name.example.com;
    root        /var/www/vhosts/example.com;
    index       index.html index.htm;
    charset     utf-8;

    access_log  /var/log/nginx/example.com.access.log  main;
    error_log   /var/log/nginx/example.com.error.log;

    include     /etc/nginx/drop;

    location / {
        return 301 http://www.example.com$request_uri;
    }
}


server {
    listen      80;
    server_name www.example.com;

# [other many configurations]
    }

 

For more detail of rewrite rules, please check Nginx's official blog and documents: 

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.
Powered by Zendesk