Variations of this question have been asked, however the scenarios do not match mine and despite my efforts I have not been able to adopt the previous answers to a working solution in my use case.
I have a page template that has a javascript application built into it. This application uses the last parameter in a URL as a parameter for an ajax request, which it runs and then produces results for.
Due to SEO concerns and client requirement, I cannot change or alter the way this request syntax functions, so I must make it work in Wordpress (page is being converted from a Ruby application)
When the client makes a request to:
https://www.wordpresssite.com/service/testing-tool/domain.com
I need to respond with the page that is built using the template at:
https://www.wordpresssite.com/service/results
This part I have working with the following rewrite rule in .htaccess
RewriteRule ^service/testing-tool/([a-z0-9.]+)$ /index.php?pagename=service/results [NC,L]
The rewrite works, however WordPress changes the URL in the browser to
https://www.wordpresssite.com/service/results
This causes the JS to fail as the domain parameter is missing, and it also doesn't meet the requirements previously mentioned.
I though after doing some research here that the issue is the redirect_canonical() action, so I tried removing it from within the template:
// Disable redirect_canonical()
add_action( 'init', 'results_tweaks' );
function results_tweaks()
{
remove_action( 'template_redirect', 'redirect_canonical' );
}
However this doesn't seem to do it. Reading the WP documentation, I suspect this is because the action is already processed by the time the page loads.
Is there another way I can override this action specifically for this template, and no others? Perhaps another way aside from removing the action?