Issue with category links in no JS mode

If you view a Discourse instance with the Googlebot Useragent so that Discourse prints the instance without JS at the top of a topic it gives a link back to the category in the format http://example.com/category/category_name

This link then redirects to back to the shorter version, http://example.com/c/category_name

The issue is if the above category is a subcategory, that second link is a 404, it should be linking to the correct location, ie http://example.com/c/parent_category/category_name

This issue doesn’t appear when you have JS enabled/aren’t the Googlebot.

Happy to give and info if wanted! You CAN repeat this on https://meta.discourse.org by using this post for example and CURLing the URL it gives back to the category listing.

macbook-air:~ $ curl -IL https://meta.discourse.org/category/wordpress
HTTP/1.1 302 Found
Server: nginx
Date: Tue, 06 Jan 2015 23:46:22 GMT
Content-Type: text/html; charset=utf-8
Status: 302 Found
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Location: https://meta.discourse.org/c/wordpress
Set-Cookie: destination_url=https%3A%2F%2Fmeta.discourse.org%2Fcategory%2Fwordpress; path=/; Secure
Set-Cookie: _forum_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiJTZmNWI0ZDRmN2VjMjgwYjcxZDUwYWU1YzBmM2YwOTMwBjsAVA%3D%3D--eec8fe7c8eff16a59a7b780f2f23311498727b2b; path=/; HttpOnly; Secure
X-Request-Id: 4ab71e35-9a4f-4bdf-a9f9-b345f42dfb0a
X-Runtime: 0.019158
X-UA-Compatible: IE=edge
Strict-Transport-Security: max-age=31415926

HTTP/1.1 404 Not Found
Server: nginx
Date: Tue, 06 Jan 2015 23:46:22 GMT
Content-Type: text/html; charset=utf-8
Vary: Accept-Encoding
Status: 404 Not Found
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Set-Cookie: destination_url=https%3A%2F%2Fmeta.discourse.org%2Fc%2Fwordpress; path=/; Secure
Set-Cookie: _forum_session=BAh7BkkiD3Nlc3Npb25faWQGOgZFVEkiJThhZTRiNmI3ZTkyNDVmMmE5MjYxNzE1OWNlZmJiNzQyBjsAVA%3D%3D--8c98906a8920b80c989a0cf916802b677fea4ed6; path=/; HttpOnly; Secure
X-Request-Id: 4869fed5-535c-4253-a440-4c4f72da1147
X-Runtime: 0.090909
Strict-Transport-Security: max-age=31415926

macbook-air:~ $
1 Like

Hmm, yeah, there are a few places we were still using the old legacy /category/foo vs /c/foo.

Definitely affected the RSS page and no-JS pages, I checked in a change to see if that helps. Not sure on subcategory handling though.

3 Likes

Thanks! I’ll wait for the commit to go into the tests-passed branch and get back to you.

Ahh. The build failed so I’ll have to wait for it to pass at this point. Travis CI - Test and Deploy Your Code with Confidence

@codinghorror your fix gets rid of the redirect, but http://example.com/c/category_name still gets a 404 since its a subcategory sadly!

Try c.url instead of c.slug if that’s used anywhere in the output?

That is a bug @eviltrout will have to fix with subcategories not displaying as proper URLs in RSS…

This happens in the non-JS versions of pages as well, btw! :smile:

Also see

https://meta.discourse.org/t/wrong-links-to-subcategory-in-noscript-tags-in-a-thread/22641

2 Likes

I’ve got a fix incoming for this. Let me know if I missed anything:

https://github.com/discourse/discourse/commit/114cc1c8510fc3fbd677f5bbfc0be6ae86877267

4 Likes

Confirmed working for me.

1 Like