Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wordpress搜索中将加号(+;)替换为破折号(-)_Wordpress_.htaccess_Permalinks - Fatal编程技术网

在Wordpress搜索中将加号(+;)替换为破折号(-)

在Wordpress搜索中将加号(+;)替换为破折号(-),wordpress,.htaccess,permalinks,Wordpress,.htaccess,Permalinks,如何使用htaccess将url中的url加号(+)更改为破折号(-)。这是我目前掌握的代码: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(#[^?&\ ]*)?\?([^&\ ]*&)?s=([^&\ ]+)[^\ ]*\ HTTP/ RewriteRule ^$ http://examp

如何使用htaccess将url中的url加号(+)更改为破折号(-)。这是我目前掌握的代码:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(#[^?&\ ]*)?\?([^&\ ]*&)?s=([^&\ ]+)[^\ ]*\ HTTP/
RewriteRule ^$ http://example.com/search/%3\.html? [R=301,L]
</IfModule>

选项+FollowSymLinks
重新启动发动机
重写cond%{u请求}^[A-Z]+\/(#[^?&\]*)?\?([^&\]*&)?s=([^&\]+)[^\]*\HTTP/
重写规则^$http://example.com/search/%3\.html?[R=301,L]
这很有效,结果如下:
http://example.com/search/key+word.html


唯一的问题是我想用dash改变plus。如果有人能提供帮助,我将不胜感激。

您可以在301规则下方插入此代码:

RewriteRule "^(search)/([^ +]*)[ +]+([^ +]*[ +].*)$" /$1/$2-$3 [L,NE]
RewriteRule "^(search)/([^ +]*)[ +]([^ +]*)$" /$1/$2-$3 [L,R=302,NE]

我决定通过使用带有以下代码的插件使之成为可能:

function seo_search_result() {
    if ( is_search() && strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false && strpos($_SERVER['REQUEST_URI'], '/search/') === false ) {
        wp_redirect(get_bloginfo('home') . '/search/' . str_replace(' ', '-', str_replace('%20', '-', get_query_var('s'). '.html')));
        exit();
    }
}

add_action('template_redirect', 'seo_search_result');

我不是在尝试,也不是在告诉你该做什么,但这不会带走搜索字符串的要点吗?这个字符串的目的是为了搜索引擎优化,它仍然显示这个单词、这个单词和这个单词的结果,因为我也更新了query.php文件。谢谢,谢谢,但是我得到了500个内部服务器错误。500没有了,但是它仍然显示加号(+),即使我把它放在301规则之上。它在我的测试中工作得非常好。确保此规则刚好低于您的301规则。如果其他规则没有将
+
放回,也要检查Firebug。