1

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:

https://example.com/dynamic-page/?parameter=xxx

and I wish to achieve this:

https://example.com/dynamic-page/xxx/

All this while using the following WP permalink structure:

/blog/%postname%/

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]
</IfModule>

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.

closed as unclear what you're asking by Stephen Ostermiller Mar 2 '18 at 15:58

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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
0

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:

http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/

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