1

我尝试了几种不同的 .htaccess 解决方案以及插件,但似乎没有任何效果。我在我的 Wordpress 网站上有不同的链接使用这样的网址:

http://www.mydomainname.com/?s=&post_type=schools&general_search=1&general_search_term=Science

我将如何将这些网址重写为: http://mydomainname.com/search/science在浏览器中?

谢谢!

这是我在 .htaccess 文件中的内容:

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]
</IfModule>
# END WordPress
4

3 回答 3

0

在您的 .htaccess 中尝试此代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]

编辑:

# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^search/(.+)$ /?s=&post_type=schools&general_search=1&general_search_term=$1 [L,QSA,NC]

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^index\.php$ - [L]

RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
于 2012-12-10T18:01:18.257 回答
0

这对我有用。

http://wpengineer.com/2258/change-the-search-url-of-wordpress/

# search redirect
# this will take anything in the query string, minus any extraneous values, and turn     them into a clean working url
RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]
RewriteRule ^$ /search/%1/? [NC,R,L]

不要忘记添加任何内容 /search/以匹配您拥有的网址。

于 2014-09-09T08:47:08.217 回答
0

简单的方法

function ctheme_search_url() {
  if ( is_search() && ! empty( $_GET['s'] ) ) {
      wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
      exit();
    }   
}
add_action( 'template_redirect', 'ctheme_search_url' );

您可以使用 wordpress 重定向功能

于 2019-06-23T16:13:53.280 回答