我有一个网址
http://classexample.com/student-details/?cname=btech&sname=xyz
我想将其转换为
http://classexample.com/student-details/btech/xyz
并且还想要使用php
的值btech和xyz我试过了
function custom_rewrite_basic() {
add_rewrite_rule('^student-details/([\w+]*)/([\w+]*)/', 'index.php/?pagename=student-details&cname=$matches[1]&sname=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_basic');
但未能成功
任何帮助将不胜感激!
答案 0 :(得分:2)
与此一起使用
function custom_rewrite_tags() {
add_rewrite_tag('%cname%', '([^&]+)');
add_rewrite_tag('%sname%', '([^&]+)');
}
add_action('init', 'custom_rewrite_tags', 10, 0);
function custom_rewrite_basic() {
add_rewrite_rule('^student-details/([\w+]*)/([\w+]*)/', 'index.php/?pagename=student-details&cname=$matches[1]&sname=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_basic');
请重置永久链接,因为保存永久链接后htaccess文件已更新