I think, therefore I blog

301 Permanent Redirect in Java

By , 6 October 2010

301 Permanent Redirect in Java

Wow, I just discovered that all the redirects I had written in my Java webapps use 302 temporary redirects. The reason this is concerning is that SEO best practise recommends using 301 permanent redirects to ensure PageRank and page reputation are attributed to the correct (target) page.

The code I was using looks like this:


The problem is of course response.sendRedirect() overrides the permanent redirect status. LOL, hooray for shortcut methods.

301 Permanent Redirect in Java

The correct way to do a permanent redirect in Java is like this:

response.setHeader("Location", newURL);

About Roger Keays

301 Permanent Redirect in Java

Roger Keays is an artist, an engineer, and a student of life. Since he left Australia in 2009, he has been living as a digital nomad in over 40 different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, and finding good food. Click here to subscribe to his weekly blog, or stalk him on Facebook and Twitter.

Leave a Comment

Please visit https://RogerKeays.com/blog/301-permanent-redirect-in-java to add your comments.

Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?