nginx redirect to www.domain
177
Solution 1
You're doing it the hard way. Here's the easy way.
server {
listen 80;
server_name example.com;
rewrite ^(.*) http://www.example.com$1 permanent;
}
server {
listen 80;
server_name www.example.com;
#The rest of your configuration goes here#
}
Solution 2
It's better to use return
instead of rewrite
, because it's faster.
server {
listen 80;
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
listen 80;
server_name www.example.com;
[...]
}
This way, we also send the client a proper status code, so that he asks the right domain in the next request.
Related videos on Youtube
Author by
Jolly Priya
Updated on September 18, 2022Comments
-
Jolly Priya over 1 year
Here i want to compile/run first ExceuteLeadTest.class and then ExceuteContactTest.class by the ant ..But while exceuting it first it comipling/running ExcecuteContactTest.java/ExceuteContactTest.class
<project> <target name="run" depends="compile"> <include name="testScript/ExceuteLeadTest.class" /> <include name="testScript/ExceuteContactTest.class" /> </target> <project>
-
ceejayoz about 11 yearsGave you an upvote, but thought I'd note that
rewrite permanent
sends a 301, too. -
Jolly Priya about 6 yearscan u please explain in detail as i am new to ANT..where to write the above tags in build.xml?
-
pamcevoy about 6 yearsI added an example of one target calling two other targets.
-
Pedro Lobito over 3 yearsShouldn't
server
have the closing tag}
?