No .htaccess file is allowed on the server because of using Nginx for a web server on our AMI.
Two ways to redirect access
- Use WordPress plugin (easy)
- 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.
- Install and activate;
- Input Source URL which means redirect from;
- Input Target URL which means redirect to;
- Save changes
- 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.confserver {
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: