From 7e09c7c6b5ad1a3000b7e3ddceca5da2b654df6d Mon Sep 17 00:00:00 2001 From: Ugnich Anton Date: Sat, 19 Apr 2014 17:45:51 +0700 Subject: Tags name case redirect --- src/java/com/juick/http/www/Discover.java | 17 +++++++++-------- src/java/com/juick/http/www/User.java | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src/java/com') diff --git a/src/java/com/juick/http/www/Discover.java b/src/java/com/juick/http/www/Discover.java index 747a3947..fec0c117 100644 --- a/src/java/com/juick/http/www/Discover.java +++ b/src/java/com/juick/http/www/Discover.java @@ -38,17 +38,18 @@ public class Discover { protected void doGet(Connection sql, Connection sqlSearch, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { com.juick.User visitor = Utils.getVisitorUser(sql, request, response); - String requesturi = request.getRequestURI(); - - com.juick.Tag paramTag = null; - String paramTagStr = null; - if (requesturi.startsWith("/tag/")) { - paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8"); - paramTag = TagQueries.getTag(sql, paramTagStr, false); - } + String paramTagStr = URLDecoder.decode(request.getRequestURI().substring(5), "UTF-8"); + com.juick.Tag paramTag = TagQueries.getTag(sql, paramTagStr, false); if (paramTag == null) { Errors.doGet404(sql, request, response); return; + } else if (!paramTag.Name.equals(paramTagStr)) { + String url = "/tag/" + paramTag.Name; + if (request.getQueryString() != null) { + url += "?" + request.getQueryString(); + } + Utils.sendPermanentRedirect(response, url); + return; } int paramBefore = 0; diff --git a/src/java/com/juick/http/www/User.java b/src/java/com/juick/http/www/User.java index ca5c122f..b584494e 100644 --- a/src/java/com/juick/http/www/User.java +++ b/src/java/com/juick/http/www/User.java @@ -57,6 +57,10 @@ public class User { if (paramTag == null) { Errors.doGet404(sql, request, response); return; + } else if (!paramTag.Name.equals(paramTagStr)) { + String url = "/" + user.UName + "/?tag=" + URLEncoder.encode(paramTag.Name, "UTF-8"); + Utils.sendPermanentRedirect(response, url); + return; } } -- cgit v1.2.3