繁体   English   中英

更改url中的值,而不是使用.htaccess进行重定向

[英]Change value in url than redirect with .htaccess

我们有一个带有某些插件的Wordpress 4.x网站,用于验证房间的可用性。 现在我们有一个这样的URL:

http://www.pluto.com/cn/check-availability/?lang=zh-TW&param1=val1&param2=value2&param3=value3& param4 = 838 &param5 = value5&param6 = value6

我们要用param4 = 631更改param4 = 838, 不是重定向到新页面:

http://www.pluto.com/zh-CN/check-availability/?lang=zh-CN&param1=val1&param2=value2&param3=value3& param4 = 631 &param5 = value5&param6 = value6

我们想使用.htaccess做到这一点。 我们该怎么做?

以下永久链接重写代码应包含在.htaccess文件中

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
 </IfModule>
# END WordPress

如果您想在url中传递参数。 以这个例子为例,请完整地通过下面的链接

 add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
 add_filter( 'query_vars','my_insert_query_vars' );
 add_action( 'wp_loaded','my_flush_rules' );

 // flush_rules() if our rules are not yet included
  function my_flush_rules(){
     $rules = get_option( 'rewrite_rules' );

   if ( ! isset( $rules['(project)/(\d*)$'] ) ) {
       global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
   }

 // Adding a new rule
  function my_insert_rewrite_rules( $rules )
{
     $newrules = array();
      $newrules['(project)/(\d*)$'] = 'index.php pagename=$matches[1]&id=$matches[2]';
    return $newrules + $rules;
 }

 // Adding the id var so that WP recognizes it
  function my_insert_query_vars( $vars )
{
   array_push($vars, 'id');
    return $vars;
   }

链接到这里

将此规则放在RewriteEngine On下面的下面:

RewriteEngine On

RewriteCond %{THE_REQUEST} \?(.*&)?param4=838(&\S*)?\sHTTP [NC]
RewriteRule ^en/check-availability/?$ %{REQUEST_URI}?%1param4=631%2 [R=302,NE,L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM