# How to remove query string from visible URL in Ring?

**URL:** https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555
**Category:** How to?
**Created:** [July 17, 2019, 4:36pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555 "2019-07-17T16:36:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [July 17, 2019, 4:36pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/1 "2019-07-17T16:36:52Z")

</div>

![Screenshot_uri](https://clojureverse.org/uploads/default/original/2X/f/f585de5ce303cde0d117b27ac70d0f63b1afe1c6.png)

My app uses Central Authentication Service (CAS) to login to the app. For those unfamiliar, this means I have a Ring middleware that redirects visitors to the server page where they login, and are then bounced back to my site with some added information, including a “?ticket=AKJF2390JKl” type string in the URL. This string is the problem; by now they are already logged in, so this means there is a time I no longer need that ticket number. However, I’m having trouble figuring out how and when to remove that string. I have various middlewares set up to look at the request so far, and I can locate two places that string appears in the request map (that’s [:params :ticket] and [:query-string]), but dissocing those two keys doesn’t change what URL the page gets in the end (e.g. “[Website Hosting - Mysite.com](http://mysite.com/?ticket=blahblah)”). Not only is this unsightly, but it results in refresh failing on the page because the ticket is one-time use (though refresh works fine when you remove the ticket string altogether after they’ve logged in, as by that point it’s cookie-powered).

So, if I can remove an end-result query string by disocing from the request map with my middleware, my question is this:

1. What do I need to dissoc in order to see a change in the end-user URL?
2. When in the middle-ware cycle do I need to perform this dissoc?

If dissoc isn’t the answer, what is?

---

<div class="post-metadata">

### Author: ![seancorfield](https://clojureverse.org/user_avatar/clojureverse.org/seancorfield/32/195_2.png) [@seancorfield](https://clojureverse.org/u/seancorfield)
#### Post date: [July 17, 2019, 7:57pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/2 "2019-07-17T19:57:01Z")

</div>

What is your app code using in the Ring request that it sees the URL with that in it?

I suspect it’s checking `:uri` directly (why?) so your middleware to `dissoc` from `:params` and modify `:query-string` is also going to need to modify `:uri` so you’ll probably need to do some regex replacement (and be careful you don’t turn `:uri` into an invalid string!).

You may also need to `dissoc` from `:query-params` (which is where URL parameters end up, _as well as in `:params`_ depending on the middleware your app is using).

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [July 17, 2019, 8:16pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/3 "2019-07-17T20:16:06Z")

</div>

I’m running reitit.ring as my middleware framework, with the handler serving to check `:query-params` and `:session` for the portion that actually uses that information. It’s not clear to me what actually generates the uri string, though, as I don’t see anything explicitly mentioning `:headers`.

---

<div class="post-metadata">

### Author: ![lilactown](https://clojureverse.org/user_avatar/clojureverse.org/lilactown/32/1221_2.png) [@lilactown](https://clojureverse.org/u/lilactown)
#### Post date: [July 17, 2019, 9:05pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/4 "2019-07-17T21:05:54Z")

</div>

You can’t “modify” the URL on the server. It is a reflection in the browser of the URL that was sent to the server. You can only redirect the user.

So if you have some flow of requests like:

```auto
GET /home --sign-in--> POST /login --success-redirect--> /success?ticket=AKJF2390JKI

```

Then you could have one more redirect at the end:

```auto
GET /success?ticket=AKJF2390JKI --redirect--> GET /success

```

---

<div class="post-metadata">

### Author: ![Webdev\_Tory](https://clojureverse.org/user_avatar/clojureverse.org/webdev_tory/32/3781_2.png) [@Webdev\_Tory](https://clojureverse.org/u/Webdev_Tory)
#### Post date: [July 22, 2019, 11:56pm UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/5 "2019-07-22T23:56:16Z")

</div>

Perfect; this explains what I’ve often seen. Somehow I got tricked into thinking there was another way.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [January 21, 2020, 11:56am UTC](https://clojureverse.org/t/how-to-remove-query-string-from-visible-url-in-ring/4555/6 "2020-01-21T11:56:16Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
