Mobile app version of vmapp.org
Login or Join
Cugini213

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

@Cugini213

Posted in: #Permalinks #QueryString #Seo #Wordpress

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:
example.com/dynamic-page/?parameter=xxx

and I wish to achieve this:
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.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Cugini213

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kimberly868

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:
www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme