I have a page that is generated dynamically based on a query parameter, which I wish to "mask" as a normal "pretty" permalink.

Right now I'm using:


and I wish to achieve this:


All this while using the following WP permalink structure:


So, currently, this is the WP part of my .htaccess:

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

The dynamic-page does not have any children, so there is not already some permalink structure "below" it. All this without messing with WP's standard permalink functionality.

  • 1
    How is this dynamic page implemented? Is it a custom created /dynamic-page/index.php file or is it powered by a WordPress plugin? – Stephen Ostermiller Mar 2 '18 at 13:12
  • It's a normal WP page whose contend depends on a query parameter, however, I have found what i needed. I'll post a response. Thank you anyway! – Hlsg Mar 2 '18 at 15:40

I have found what I was looking for. Here is what I'm using:

function add_query_vars($vars) {
    $vars[] = "parameter";
    return $vars;
add_filter('query_vars', 'add_query_vars');

The above code adds the parameter query variable to the list WP looks for.

function add_rewrite_rules($rules) {
    $newrules = array('dynamic-page/([^/]+)/?$' => 'index.php?pagename=dynamic-page&parameter=$matches[1]');
    $rules = $newrules + $rules;
    return $rules;
add_filter('rewrite_rules_array', 'add_rewrite_rules');

The above does the actual URL rewrite, in the context provided by the original question.

More information can be found in this tutorial:


| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.