Change value in url than redirect with .htaccess

we have a WordPress 4.x website with some plugin that verify the availability of rooms. Now we have an url like this:

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

Read More

We want to change param4=838 with param4=631 than redirect to the new page:

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

We want to do this with .htaccess. How can we do that?

Related posts

2 comments

  1. Place this rule just below RewriteEngine On line:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} ?(.*&)?param4=838(&S*)?sHTTP [NC]
    RewriteRule ^en/check-availability/?$ %{REQUEST_URI}?%1param4=631%2 [R=302,NE,L]
    
  2. The following permalink rewrite code should be included in your .htaccess file

    # 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
    

    And if you want to be passing arguments in url. Take this example and kindly go through the below link completely

     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;
       }
    

    link here

Comments are closed.