0

I have param with slash, it encodes to the UTF-8, but server return me 404 error. How to exclude slash or %2F from my last param. In my project I use only annotations.

I can't change any structure and urls, because my site is in top position and Google told me to fix this, because indexed urls return 404.

Example of urls, slash :

/ru/weather/7/Neustad%2FNord_DE

/de/weather7/Reichenbach%2FVogtland_DE

Have controller

    @RequestMapping({
            "/",
            "/forecast/{locationRequest:.+}",
            "/forecast/today/{locationRequest:.+}",
            "/weather/today/{locationRequest:.+}",
            "/weather/map/{locationRequest:.+}",
            "/forecast/map/{locationRequest:.+}",
            "/forecast/tomorrow/{locationRequest:.+}",
            "/weather/tomorrow/{locationRequest:.+}",
            "/weather/history1/{locationRequest:.+}",
            "/weather/history3/{locationRequest:.+}",
            "/forecast/3/{locationRequest:.+}",
            "/weather/3/{locationRequest:.+}",
            "/forecast/5/{locationRequest:.+}",
            "/weather/5/{locationRequest:.+}",
            "/forecast/7/{locationRequest:.+}",
            "/weather/7/{locationRequest:.+}",
            "/forecast/10/{locationRequest:.+}",
            "/weather/10/{locationRequest:.+}",
            "/forecast/14/{locationRequest:.+}",
            "/weather/14/{locationRequest:./+}",
            "/forecast/hour-by-hour1/{locationRequest:.+}",
            "/weather/hour-by-hour1/{locationRequest:.+}",
            "/forecast/hour-by-hour3/{locationRequest:.+}",
            "/forecast/detailed3/{locationRequest:.+}",
            "/forecast/detailed1/{locationRequest:.+}",
            "/weather/detailed1/{locationRequest:.+}",
            "/weather/detailed3/{locationRequest:.+}",
            "/weather/hour-by-hour3/{locationRequest:.+}",
            "/weather/widgets/{locationRequest:.+}",
            "/weather/climate/{locationRequest:.+}"
    })
    public ModelAndView index(@PathVariable(value = "locationRequest") String locationRequest) {}

Also in my application.properties have

org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true

In main class also i made

    System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
Alex Ul
  • 19
  • 7
  • 1
    Documentation for [`ALLOW_ENCODED_SLASH`](https://tomcat.apache.org/tomcat-8.5-doc/config/systemprops.html#Security) says: *"If this is true '%2F' and '%5C' will be permitted as path delimiters"*. But you do not want `%2F` to be treated as a *path delimiter*, so maybe remove that. – Andreas Mar 21 '18 at 21:55
  • I can't remove it, this city is used by users in google, please make better answer – Alex Ul Mar 21 '18 at 21:56
  • 1
    What does anything you just said have to do with not setting `ALLOW_ENCODED_SLASH` to `true`? – Andreas Mar 21 '18 at 21:58
  • I think I need sth to do with regex {locationRequest:.+} – Alex Ul Mar 21 '18 at 22:01
  • ALLOW_ENCODED_SLASH doesn't help me( – Alex Ul Mar 21 '18 at 22:02
  • Without this prop my application doesn't work – Alex Ul Mar 21 '18 at 22:03
  • ALLOW_ENCODED_SLASH is the *problem,* amd if you can't get rid of it for other reasons you cannot use / in your parameter values. You can't have it both ways. – user207421 Mar 21 '18 at 22:07
  • Ok, early I had 404 of my application after I have deleted ALLOW_ENCODED_SLASH, my application doesn't go to my application. I can't remove this one, because %2F isn't allowed – Alex Ul Mar 21 '18 at 22:10
  • Another contradiction in terms. – user207421 Mar 21 '18 at 22:11
  • Ok, if i delete ALLOW_ENCODED_SLASH now my application doesn't work again, how to fix it? It looks like slash which isn't allowed, but I need it in param only not like url – Alex Ul Mar 21 '18 at 22:12
  • I've answered that. You can't have both ways. You simply have to make up,your mind. *Either* use ALLOW_ENCODED_SLASH *or* use encoded / in your parameter values. You cannot accomplish both at the same time. It is a contradiction in terms. – user207421 Mar 21 '18 at 22:15
  • But it is necessary for me – Alex Ul Mar 21 '18 at 22:16
  • It is impossible for anybody. It is pointless to keep restating your contradiction terms. You are asking for a square circle. – user207421 Mar 21 '18 at 22:16
  • Easiest way to make it like any param /**, and split the url with slash, and take the last param, is any ideas? – Alex Ul Mar 21 '18 at 22:19
  • **WHAT PART OF 'CONTRADICTION IN TERMS' DON'T YOU UNDERSTAND?** – user207421 Mar 21 '18 at 22:20
  • U don't understand that I need this way with slash in my param – Alex Ul Mar 21 '18 at 22:21
  • I can't remove 100 urls from Google SEO, it is impossible, I will loose my users and money – Alex Ul Mar 21 '18 at 22:22
  • Google told me about 404 error, I don't need to use CONTRADICTION IN TERMS, for me it is necessary – Alex Ul Mar 21 '18 at 22:22

0 Answers0