WordPress.org

Ready to get started?Download WordPress

Forums

Search Permalink: replace string "?s=" to permalink structure (4 posts)

  1. webbando
    Member
    Posted 1 month ago #

    Hi,

    is it possible to change the normal string ?s= to a permalink structure?

    In particular I need to have the following url:

    http://www.sitedomani.com/search/keyword1-keyword2-keyword3

    instead of:
    http://www.sitedomani.com/?s=keyword1+keyword2+keyword3

    So, I need to delete "?s=" and replate the "+" with the "-".

    Is it possible?

  2. bcworkz
    Member
    Posted 1 month ago #

    Yes! You will mainly be using add_rewrite_rule(). This basically accepts a permalink like you envision and rewrites it back the way it is normally behind the scenes so the request parser knows that it's a search request.

    You'll also need to use the 'request' filter to convert the hyphens back to pluses.

  3. webbando
    Member
    Posted 1 month ago #

    Hi bcworkz.. Thanks a lot for your reply.

    Do you already have the code (php and htaccess) that I need?

    Thanks a lot again for your time.

  4. bcworkz
    Member
    Posted 1 month ago #

    Sorry, no. Truth be told, I haven't fully figured out rewrites. Sometimes they work fine, other times not. I haven't figured out an efficient debug method to determine why things don't work either. I can suggest you ensure your regexp is working independent of rewrites before attempting to use it in rewrites.

    Also that when using the WP Rewrite API, you don't need to be concerned about .htaccess, WP will revise its entry if it needs to. It's also possible to use a solely .htacces solution independent of the WP Rewrite API. Hopefully yours is one of those implementations that work fine right away. Good luck!

Reply

You must log in to post.

About this Topic

Tags

No tags yet.