Opened 14 years ago
Closed 13 years ago
#2681 closed defect (bug) (fixed)
Canonicalization of Buddypress URLs
Reported by: | lucianop | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 1.6 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Core | Keywords: | has-patch |
Cc: |
Description
When I visit a BuddyPress-generated URL (such as http://example.com/activity), I am not redirected to a properly canonicalized url.
For example, I can go to:
http://example.com/activity
http://example.com/activity/
In Wordpress, the default behavior is whether I type the url without trailing slash, I get redirected to the canonicalized version (with trailing slash).
Attachments (2)
Change History (9)
#2
@
14 years ago
Interestingly, changing Wordpress' canonical action hook from "template_redirect" to "get_header" fixes this for BuddyPress.
No time for a patch, but try changing this line in /wp-includes/canonical.php:
add_action('template_redirect', 'redirect_canonical');
to:
add_action( 'get_header', 'redirect_canonical', 0 );
Not sure if there are any side-effects with doing this.
#3
@
14 years ago
- Keywords has-patch added; url canonicalization removed
The patch checks if the current page is a blog page ( WP page, post, archive, etc. ) with bp_is_blog_page(), then adds a hook to "get_header" with a priority of zero, so it runs first, directly after "template_redirect"; "get_header" is the action following "template_redirect".
---
Tested lightly; it redirects BP pages to their trailingslashit equivalent.
Anchors in URLs are preserved; haven't checked queries, but should work as well.
#4
@
13 years ago
- Owner set to boonebgorges
- Severity set to normal
- Status changed from new to assigned
Related to #1741
#5
@
13 years ago
2681.002.patch is the function that I've come up with to handle this. I've hooked it to a new do_action() in bp_core_load_template(), so that the redirect only takes place for pages that are viewable in a browser (mimicking the fact that WP does the redirect at template_redirect).
This patch will have to be accompanied by a gigantic audit of our own redirect and URL-building functions. We want to avoid redirects where possible, so we should be building our URLs appropriately - with the trailing slash. I'll work on it. In the meantime, feedback welcome on 2681.002.
This would be worth doing but it probably won't happen for 1.3 unless someone provides a patch.