'.htaccess rewrite without redirect / Wordpress

I want to rewrite an URL so that "few_words_Keyword" is shown in the browser but the page display /directory/Keyword

In my htaccess I have following :

RewriteEngine On
Options +FollowSymLinks -MultiViews
RewriteBase /
RewriteRule few_words_(.*)$ /directory/$1 [L,R,NC]

It works with R and it redirects to the page /directory/Keyword but without R I get an 404 error.

Edit : the URL /directory/$1 is not "real" it is another redirection which is managed by 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>

Can you help me ?

Many thanks in advance



Solution 1:[1]

Solved with the documentation here https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

I put it in the function.php of my child theme

/* Redirection */ 
  function custom_rewrite_rule() {
    add_rewrite_rule('^xxxxxxxxxxxxx(.*)','/index.php?p=123&var=$matches[1]','top');
  }
  add_action('init', 'custom_rewrite_rule', 10, 0);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user161783