what is the equivalent rewrite rule in nginx
I was having this rewrite rule in Apache2
RewriteRule country/usa[/]*$ /en/country/united-states [L,R=301,NC]
I have tried to build an equivalent rewrite rule in nginx like this
server {
rewrite ^country/usa[/]*$ /en/country/united-states last;
#the remaining of the virtual host
}
but this didn’t work
any idea of how to do this?
Thanks for your help
Something similar to the code below should do the work:
server {
...
rewrite ^/country/usa$ /en/country/united-states permanent;
}
This will redirect only /country/usa and /country/usa/ with a 301 Moved Permanently status. The other way option is
server {
...
rewrite ^/country/usa([/])?(.*)$ /en/country/united-states/$2 permanent;
}
which will redirect everything after and including /country/usa to the new location.
For example /country/usa/testing will go to /en/country/united-states/testing.
Check more discussion of this question.
Related posts:
Leave a comment
Recent Posts
- What is the easiest way to upgrade my existing Perl 5.14 to Perl 5.16 on FreeBSD 9 using the ports system?
- Know if mysql has done its job
- Redirect https .com to https .co.uk without a valid SSL cert on .com without DNS change
- Why is it a bad idea to use customer email as from address
- 100% packets dropped on first RX queue on 3/5 raid6 iSCSI NAS devices using intel igb (resolved)
Tags
active-directory
amazon-ec2
apache
apache2
backup
bash
centos
cisco
command-line
debian
dns
email
exchange
firewall
iis
iis7
iptables
linux
macosx
monitoring
mysql
networking
nginx
performance
permissions
php
postfix
raid
security
sql-server
sql-server-2005
sql-server-2008
ssh
ssl
ubuntu
unix
virtualization
vpn
webserver
windows
windows-7
windows-server-2003
windows-server-2008
windows-server-2008-r2
windows-xp





