I've integrated a custom PHP script within my wordpress instalation (with theme page-template).
The page is /islands/island/
and I get the islandId with GET paramater. So the URL looks like https://website.com/islands/island/?iid=1
But now I want to rewrite the url to be like this: https://website.com/islands/island/1
I already tried edditing the .htaccess but with no luck.
After some research I found editing .htaccess is not the right way to do this. So I used the followingn code and added it to my theme's function.php.
function add_directory_rewrite() {
add_rewrite_tag("%iid%", '([^/]*)');
add_rewrite_rule('^islands/island/([^/]*)', 'index.php?pagename=islands/island&iid=$matches[1]', 'top');
}
add_action( 'init', 'add_directory_rewrite' );
But unfortunately it is not working. When I browse to the page http://website.com/islands/island/1
it redirects to http://website.com/islands/island/
.
Am I missing something?