[wp-trac] [WordPress Trac] #10552: Add get_search_link()
WordPress Trac
wp-trac at lists.automattic.com
Thu Feb 25 08:24:32 UTC 2010
#10552: Add get_search_link()
-------------------------+--------------------------------------------------
Reporter: sirzooro | Owner: dd32
Type: enhancement | Status: reviewing
Priority: normal | Milestone: 3.0
Component: Permalinks | Version: 2.8.3
Severity: normal | Keywords: needs-patch needs-testing
-------------------------+--------------------------------------------------
Comment(by dd32):
> When you do not encode slahses (url like site.com/search/foo/bar/), you
will get 404 served by WP.
This is due to Apache discarding the invalid URL.
/search/test%2Fpost/ is NOT a valid url, however ?s=test%2Fpost IS a valid
url. %2F may appear in a URL query string, but not its path.
Valid URL's would be in the form of:
{{{
http://localhost/wordpress-commit/search/test/post/
OR
http://localhost/wordpress-commit/search/test%25Fpost/
}}}
The problem with the 2nd one however, Is that WordPress doesnt double-
urldecode the link.
It seems Apache has a 'AllowEncodedSlashes' option, which transforms %2F
to / before its run by the plugins.
one way around this is:
{{{
function get_search_link( $query = '' ) {
global $wp_rewrite;
if ( empty($query) )
$search = get_search_query();
else
$search = stripslashes($query);
$permalink = $wp_rewrite->get_search_permastruct();
if ( empty( $permalink ) ) {
$permalink = home_url('?s=' . urlencode($search) );
} else {
$search = urlencode($search);
$search = str_replace('%2F', '/', $search); // %2F(/) is
not valid within a URL, Pre-encode it so its double-encoded.
$permalink = str_replace( '%search%', $search, $permalink
);
$permalink = home_url( user_trailingslashit( $permalink,
'search' ) );
}
return apply_filters( 'search_link', $permalink, $search );
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10552#comment:13>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list