My Page Custom URL: http://abcd.com/watch?name=video-title
How can I change this url to http://abcd.com/watch/video-title
where watch
is a custom page?
My functions.php
code:
function create_new_url_querystring()
{
add_rewrite_rule(
'^watch/([^/]*)$',
'index.php?page_id=3&name=$matches[1]',
'top'
);
}
add_action('init', 'create_new_url_querystring');
1 Answer
You’re using the reserved public query variable name
as your custom one.
It can e.g. affect the canonical redirect by setting page_id
and name
for a different page.
Change it to something else to avoid possible name collision, like kenan_video_slug
:
add_rewrite_rule(
'^watch/([^/]*)$',
'index.php?pagename=watch&kenan_video_slug=$matches[1]',
'top'
);
Note that your rewrite will override the content pagination for the watch
page.
Remember to flush the rewrite rules.