2010-05-26 21 views
1
Options +FollowSymLinks 
RewriteEngine On 
RewriteCond %{THE_REQUEST} ^[A-Z]+ /(#[^?& ]*)??([^& ]*&)?s=([^& ]+)[^ ]* HTTP/ 
RewriteRule ^$ http://wordpressblog.com/search/%3? [R=301,L] 

目前我使用上面的.htaccess mod_rewrite的規則,WordPress默認搜索永久轉換:使用 - 在WordPress搜索永久相反+的

http://wordpressblog.com/?s=key+word 

成漂亮的永久鏈接是這樣的:

http://wordpressblog.com/search/key+word 

我的問題是:以上mod_rewrite規則的哪一部分,我需要更改以獲得更好的永久鏈接,如下所示:

http://wordpressblog.com/search/key-word.html 

謝謝。

回答

0

如果我認爲是正確的,當你重定向這個;

?s=hello+world 

to this;

/search/hello-world.html 

WordPress會實際上搜索「HELLO-world.html」,我懷疑你會得到任何結果(假設'你好+世界,那裏的加是URL解碼,以實際的「空間」 ,確實返回結果)。

因此,在進行搜索之前,您還需要插入WordPress,以便將搜索字詞清理回原來的樣子。

加上它看起來a pain to do character replacement in Apache rewrites - 你必須爲每個'加'事件編寫規則。

如果我是你,我會盡全力在WordPress內部使用PHP。如果你喜歡這種聲音,我可以發佈一個解決方案?

+0

肯定的是,任何一種解決方案是值得歡迎的。謝謝。 – poer 2010-05-30 10:58:22

1

這對我有效。當我啓用了固定鏈接時,搜索不起作用。

將此JQUERY SCRIPT添加到您的THEME header.php文件中AFTER wp_head();標籤。

爲此,您還必須通過在header.php中添加<?php wp_enqueue_script('jquery'); ?>來啓用jquery BEFORE wp_head();標籤。

例子:

<?php wp_enqueue_script('jquery'); ?> 
<?php 
    /* We add some JavaScript to pages with the comment form 
    * to support sites with threaded comments (when in use). 
    */ 
    if (is_singular() && get_option('thread_comments')) 
     wp_enqueue_script('comment-reply'); 

    /* Always have wp_head() just before the closing </head> 
    * tag of your theme, or you will break many plugins, which 
    * generally use this hook to add elements to <head> such 
    * as styles, scripts, and meta tags. 
    */ 
    wp_head(); 

?> 
<script type="text/javascript"> 
    jQuery(document).ready(function() { 
     jQuery("#searchform").live('submit',function(){ 

      location.href='/search/' + encodeURIComponent(jQuery("#s").val()).replace(/%20/g, '+'); return false;  

     }); 
    }); 
</script>