It’s easy. Just add this hook for template_redirect
action and it will redirect your search queries to nice url:
function wpse8170_search_url_redirect() {
if ( is_search() && !empty( $_GET['s'] ) ) {
wp_redirect( home_url( "/something/" . urlencode( get_query_var( 's' ) ) ) );
exit;
}
}
add_action( 'template_redirect', 'wpse8170_search_url_redirect' );
Add to your .htaccess
file:
# search redirect
# this will take anything in the query string, minus any extraneous values, and turn them into a clean working url
RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]
Related Posts:
- How to remove “http://” When Echoing URL?
- WordPress Move to SSL How to Update Media Assets to HTTPS?
- How to create a custom search for custom post type?
- How do you retrieve a post by slug name through REST API?
- Why “?v=hash” is added to my URLs? [closed]
- Detecting a WordPress URL without doing a full HTTP GET?
- How does WordPress generate URL slugs?
- How does routing on wordpress work?
- Redirecting to old domain after migration
- Custom plugin route in WordPress
- Why is ?doing_wp_cron being appended to my URLs
- Unwanted media library URLs in posts?
- How to remove file versions from the file source links in wp_head?
- use query string in URL to display content on the page
- Change default URL path (/blog/) of blog posts
- Difference between esc_url() and esc_url_raw()
- How to Change 404 page title
- How to deal with WordPress on localhost
- Problem with guids and absolute links
- WordPress Multiple Category Search
- WordPress Permalink changes to question mark (?) in URL
- Search Custom Post Type Pages and Custom Fields in 2 Dropdowns?
- How to convert the file path to a URL of the same file?
- Add menu and submenu in admin with a URL instead of slug?
- Search multiple custom fields by using meta_query
- Update media file url in wordpress media library
- Dealing with Many Meta Values, 30+
- Why is WordPress saving full-urls to the database?
- Custom slug in front of search URL
- Natural URL Design and static front page
- Search/Replace for editor in HTML-mode
- Get taxonomy slug from url
- Load images with http urls inside https post
- Remove All Query Arg
- Pulling a parameter out of the URL of a WP link without “?” or being sent to a different page
- How to remove /index.php/ from URL’s
- Run WordPress frontend and backend in different domains
- How to set global variable in functions.php
- Force the Website URL to Include “www” and to be Upper Case?
- Change logo url link
- WordPress and $_GET Params
- Modify search function in WordPress (TwentyTwelve)
- Can’t login after my site was moved to a new server
- WPML Get url without outputting
- Filter results with custom field values and dropdown
- How to customize search result page title?
- List of default WordPress URLs
- Why WP encodes UNICODE (UTF8) containing urls? Any drawbacks of UNICODE url?
- Adding a hook to ‘parse_request’ so that siteurl/pagename/xyz ignores “xyz”
- How to have numeric URLs in Posts and Pages
- Unable to load static front page on home url
- Creating search form for custom database table
- How to build custom WP admin with custom URLs
- Force home page to be https?
- Search through custom post type and custom fields takes 5 minutes
- Why WordPress automatically removes http from the url of my website’s sub domain?
- Adding Custom Link anchors in the top menu that points to specific sections of the site home page
- add_query_arg() One Key with multiple values
- Weird: /?name in URL leads to blog
- Is there a way to do multiple ordering on a multiple meta_query?
- I am Looking to append URL Parameter to all URLs
- How do I amend the fixed “author” part in the URL?
- Dynamic URL generates dynamic content
- Moving wp-content outside of web root?
- Pages redirected to attachment post
- Generate one time URL
- In Settings>>General I am missing some fields
- Search results with custom loop don’t update when paged
- Change homepage url
- Create subpage /user/ or /my-profile/ like /author/ with additional query like /user/user123
- Multiple keyword search
- Search results ordered by custom post types are not grouped
- Display WordPress Search
- As soon as I add a custom query_var using the filter, my pages point to an archive page – why?
- Customise search form in the Widget
- Search results URL without query string variables
- Comment filtering (search)
- Is dynamic URL possible in WordPress
- Combine multiple words in custom meta search query
- Adding target and _blank as it’s value to the allowedtags
- How to update media links in WordPress after migration?
- permalink for category pages and posts
- Accessing the Current URL in a Text Widget for a Facebook Share Button?
- Is ‘name’ a reserved word in URL’s?
- get_site_url is not returning anything?
- Check what is at URI (post, archive, etc…)
- wp_enqueue_scripts not called on search page?
- Custom search page and search by title, content and tag
- add_rewrite_rule not working for language specific characters
- Get url from file uploaded in Media Library
- How to create a custom page base on URL for WordPress?
- How to make menu items active based on hash
- Use image url with add_image_size
- Global, network-wide shortcodes or text replace functions
- Multiple domain names for one site
- How to change URL Custom Page?
- How to always rewrite author archive page URL even if the author does not have a post
- Extending wordpress search to include excerpts and taxonomies?
- How to fix unchanged URLs in Database after running serialized search and replace script?
- Passing page url into a custom field via the Press-This bookmarklet