[wp-hackers] Rewriting search URL

Peak Discharge chmoka at gmail.com
Sat Apr 23 22:29:51 GMT 2005


That form of yours doesn'k either, the request looks like 
http://www.unicorns.com/search/?s=test

On 4/22/05, Terrence Wood <tdw at funkive.com> wrote: 
> 
> Here's a proof of concept for rewriting a query string into a url...
> works on apache. I'll leave integrating it in WP for you.
> 
> 1. Create a test file 'testsearch.php' and put it in your WP root dir
> with the following:
> 
> <?php
> // put search term back in form if exists
> $str = (isset($_REQUEST['s'])) ? 'value="'.$_REQUEST['s'].'"': null;
> // always submit form to your-WP-install/search/
> $self = preg_replace ( '@/search.+@', '/search/',
> $_SERVER['REQUEST_URI'] );
> // note: form must be GET, POST won't work
> ?>
> <form action="<?php echo $self; ?>" method="get">
> <input type="text" name="s" <?php echo $str; ?> />
> <input type="submit" value="search" />
> </form>
> 
> 2. Put these rules in your .htaccess above your WP rules, changing
> your-WP-install as needed:
> 
> RewriteEngine on
> RewriteBase /your-WP-install/
> # get the query string, append to path and redirect.
> # '?' in the rewriteRule removes query string from URL
> # 'R' is an external redirect so new URL appears in location bar
> RewriteCond %{QUERY_STRING} s=(.+)
> RewriteRule ^search/?$ search/%1/? [R]
> # redirect to our search page, scraping URL for querystring if it exists
> RewriteRule ^search/([^/]+)?/?$ testsearch.php?s=$1 [L]
> 
> HTH
> Terrence Wood
> 
> On 22 Apr 2005, at 10:30 AM, Peak Discharge wrote:
> 
> > That changes my url into the form of http://www.unicorns.com/?s=string,
> > which is a progress. The aim, however is to change all search urls to
> > http://www.unicorns.com/search/string
> 
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> 



-- 
best regards, chmoka
mailto:chmoka at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://comox.textdrive.com/pipermail/wp-hackers/attachments/20050423/a8a71baa/attachment.html


More information about the wp-hackers mailing list