Isn’t that just because you’ve put ! empty( $_GET['s'] )
in your IF statement? Is your search page accessible when you remove that part?
EDIT:
Or maybe change your function to something like this (untested):
function wpb_change_search_url() {
if ( is_search() ) {
if ( isset( $_GET['s'] ) ) {
wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
exit();
} else {
wp_redirect( home_url( "/search/" ) );
exit();
}
}
}
add_action( 'template_redirect', 'wpb_change_search_url' );
Related Posts:
- Custom slug in front of search URL
- add_rewrite_rule not working for language specific characters
- Use a template file for a specific url without creating a page
- Does WordPress keep track of a post’s URL history and provide automatic redirects?
- Using custom/dynamic “slug” for a page
- Unique URL Every Time
- Display posts with author in the url with custom post types
- Clash of the rewrites
- How do i change the search permanent links
- Will references to ugly links automatically redirect to their pretty url permalink?
- How to create a specific frontend URL (not a Page) from a theme or plugin?
- Why does wordpress still strip my query var?
- Appending numbers to url do not break the link
- Hijacking the URL for filtering
- custom htaccess rewrite rule for page
- Tricky URL rewrite with custom values in url
- How to change page URLs to “www.site.com/page” instead of “example.com/blog/page” but keep post URLs as “example.com/blog/post”?
- Add_query_arg + two times the same argument?
- WordPress 404 unless there is a space in url
- redirect 301 old url to new url
- Change WordPress comments url / word
- Add a query string to ALL links on site
- Add rewrite rule for rewrite endpoint
- Migrating a page to be an article
- Allow single quote in URLs
- How to get “extended” path info from URL in a plugin
- How to check current URL for endpoint in a template file?
- How to perform a query at the URL?
- Is there a way to create alias without using htacess, permalinks or delving into code?
- Define orderby in url
- WordPress .htaccess – route other URLs to another app
- Is there a ‘rake routes’ for wordpress?
- Changing RSS feed URL structure
- Creating a dynamic URL structure
- add_rewrite_rule fro html to another url not working
- Preserve Domain Alias
- WordPress redirects non-existing url to existing ones – how to disable
- How to rewrite url wordpress?
- How to disable URL rewriting for specific URLs?
- How to building pretty URLs to reflect category hierarchy?
- How do I display only the parent page in the url
- Rewrite custom post type URL parameters
- Wildcard forward all posts and pages with few exceptions
- Help with Rewrite Rule for Custom Post Type with Query String
- A clean custom rewrite rule for weekly archives
- I want to add a new tag to WordPress URL permastruct
- Add language prefix to permalinks
- Why is WordPress rewriting absolute URLs on staging site to include staging prefix when we manually point them at the live site?
- React Router with WordPress
- How to redirect large amount of URLs?
- WordPress search rewriting
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- Per Page Permalink Structure for Page Post Type
- ngnix Url rewrite doesn’t work
- Understanding the query string after .htaccess rewrite
- Rewrite /category/cars into /topics/cars
- URL renaming issue
- Removing “www” from a site URL
- Adding a query string to only one page url
- Clean Custom URL for Serach + Custom Taxonomy
- Weird characters behind every single link and images
- How to use wp rewrite to hide form action url?
- Change /search to /somethingelse
- How do I get posts to appear at mydomain.com/blog?
- get variable from url?
- remove archive from url :: marketpress
- Changing the wordpress default search url to something like – …example.com/search?query=keyword
- add_rewrite_rule with optional parameters
- WordPress is adding “category” word before my actual category name in url (and this is unsolicited)
- Append a parametter at first or last to a certain URL
- Allowing multiple URLs for same Post
- How to create dynamic URLs on WordPress?
- Redirect empty search to another page
- Dynamic URL with rewrite rule not working
- How to Update / Change URL when Popup Modal Loads?
- How to add Search URL parameters to a Page Template Page for Custom Post Type
- Multiple permalink with and without category for same post
- Passing a variable to hyperlink text?
- Param causing 404
- Rewrite URL for Search + Special Characters / Umlaute
- url redirect none www to www
- Root-relative paths being rewritten on ‘Edit Page’ [closed]
- How to remove Base URL Duplication?
- Get custom posts by segment of the URL
- Get parameters and custom page template
- Direct Dynamic URL in root to a location within template
- Use Parent Pages for URL Structure without Landing Page
- taxonomy term in URL slug won’t forward to the correct term for custom post like it does for default categories/normal posts
- Remove Page Slug from URL
- How to create short urls for sharing and downloadable content?
- How to stop WordPress creating URLs that don’t exist
- Change the search URL
- Rename page URL
- How to prevent URL-modification when page title contains digits only?
- How to exclude my home page from url of my internal pages?
- How do I display a friendly URL link in the frontend?
- Please give me the rewrite rules for my ugly urls
- Lost WordPress website access after changing URL [closed]
- Remove url parameter using wordpress
- How to make custom WordPress page deliver search results