When a subcategory is moved to a different parent category, the previous URL should redirect to the new one


(Speck Kevin Pratt) #1

I am wanting to create a new top-level category and move some of the subcategories in another that is overburdened to that new top-level category. But if I change the parent category of any of those sub-categories, all my links are broken and I have to go back everywhere and change them.

I saw that a nginx solution was suggested. Should I use that? If so can someone point me to the best way to do that? Is the default docker droplet on digitalocean an nginx server? I’m a little confused on what’s actually serving the discourse install.

Thanks

Continuing the discussion from When a category is renamed, the previous URL should redirect to the new one:


(Sam Saffron) #2

A 500 is a bug we should fix, if we are to go with a redirect it would have to be temporary, seems odd to carry around something like this forever.

Now, if you just want to create this yourself, why not use the permalink section we have in admin?


(Charles Walter) #3

Once links are out there in the Internet, and then the URL is renamed, it would be nice if the 301 redirects could remain until someone needed to reuse the URL. What’s the harm?


(Sam Saffron) #4

It just feel like carrying a lot of logic around,

  1. If user moved subcategory to another parent
  2. OR, user renamed category
  3. AND, category/subcategory was alive for more than ??? days
  4. Create a permalink
  5. Expire when reused

I am not categorically against, it is just lots of work


(Charles Walter) #5

Another option is to just let admins manage a redirect table for 301s, so
if there’s a way to get a log of 404s or 500 errors, we could handle these
errors more smoothly ourselves.


(Kane York) #6

That’s available at /admin/customize/permalinks .


(Charles Walter) #7

Cool. So if Discourse just added a unqiue <title> for page not found (ex: $sitename - Page Not Found), then admins can better analyze which URLs are generating errors via Google Analytics.

From there, we should be able to take responsibility for making sure we handle any errors properly.


(Charles Walter) #8

So I tried using permalinks for the first time, but I can’t figure out if I’m doing something wrong.

We had created a Shakira category here originally:
http://www.helloforos.com/c/entretenimiento/shakira

Now it is located here:

I’ve tried entering in both the absolute URL and the relative URL as redirects to the new URL, but I continue to get 404s.

Not sure if it’s because I am specifying a full URL. I haven’t figured out where to grab the category ID.


(Arpit Jalan) #9

Permalinks don’t support reserved Discourse routes (c/:category / c/:parent_category/:category) at the moment.

I will try to make Permalinks work for reserved Discourse routes in case the reserved route is giving 404. Added on my list.


(Arpit Jalan) #10

You’re Doing It Wrong™ :smile:

The correct way to add Permalink for this case is to add c/entretenimiento/shakira in URL field and provide Category ID for /celebridades/shakira (which is 116), like this:

Now since you are a hosted customer and don’t have access to Rails console, I can understand that getting Category ID will be tricky. So, just PM me whenever you need to know the ID for particular category. :smile:

Also as I mentioned above, currently Permalinks don’t support reserved Discourse routes. I working on a fix for this and will post here as soon as the fix is in place.


(Mittineague) #11

Are the id values found in /categories.json not the correct id values needed?


(Kane York) #12

Actually, @charleswalter should use /site.json because it’s a subcategory, but yes.


(Charles Walter) #13

Thanks guys. I’ll wait until the fix is made before doing any further category moves.


(Charles Walter) #14

Hi @techAPJ, just wondering where this might be on your list :). We have a number of subcategories we’d like to move, but want to avoid the 404s. Appreciate your help on this!


(Arpit Jalan) #15

Hey Charles! Will try to get it done by Monday day end. :calendar:


(Arpit Jalan) #16

Okay, Permalinks now support Discourse category routes (c/category or c/sub/category) :gift:

https://github.com/discourse/discourse/commit/193f04842ebb8e842932e5fb77449278f202d183


(Lisa Wess) #17

Happy to see this; we are considering making several categories subcategories and I was just struggling with this exact issue. Thanks all.


(Kane York) #18

Perhaps you should move that code to ApplicationController in the rescue_from Discourse::NotFound block so that all routes will work.


(Arpit Jalan) #19

I thought about doing that, but then I realized that an extra query will run every time a 404 page is served. Will this affect performance?


(Kane York) #20

Eh, 404 pages should be uncommon enough that it won’t be a problem. Besides, ir’s already doing two topic list queries, an exists query on a usually-empty table shouldn’t be a problem.