admin管理员组文章数量:1415476
My site uses a plugin Easy Digital Downloads, which creates products that are of url structure, sitename/downloads/{Product}
I want to change them to sitename/{product}
For example, / is one of my product, i want to make it appear at /
For this they provide ability to change slug define('EDD_SLUG', 'my-downloads-slug');
via php, in this use case, i could change it to something else, but not blank, the default slug is downloads
and i wanted no slug, so made it blank, which didn't work.
I rather tried using htaccess, I am having trouble with that too.
I tried this: RewriteRule ^downloads/(.*)$ $1
But it had no impact andmy links remained same, so please help me rewrite them
My site uses a plugin Easy Digital Downloads, which creates products that are of url structure, sitename/downloads/{Product}
I want to change them to sitename/{product}
For example, https://milyin/downloads/steve-jobs-reality-is-malleable/ is one of my product, i want to make it appear at https://milyin/steve-jobs-reality-is-malleable/
For this they provide ability to change slug define('EDD_SLUG', 'my-downloads-slug');
via php, in this use case, i could change it to something else, but not blank, the default slug is downloads
and i wanted no slug, so made it blank, which didn't work.
I rather tried using htaccess, I am having trouble with that too.
I tried this: RewriteRule ^downloads/(.*)$ $1
But it had no impact andmy links remained same, so please help me rewrite them
Share Improve this question asked Sep 16, 2019 at 13:10 Aditya AgarwalAditya Agarwal 2764 silver badges22 bronze badges1 Answer
Reset to default 0You're looking to remove a post-type slug completely from the url. This is documented in this answer. Remember that after making any changes to post urls, you should resave your permalink structure for the changes to fully take effect.
Edit: You can additionally redirect from the old location (with the slug), this way:
function na_redirect_slug_requests() {
$post = get_queried_object();
// If our custom-post-type
if ( ! empty( $post->post_type ) && 'events' === $post->post_type ) {
$url = get_permalink( $post );
// And the custom-post's url doesn't match the one we're looking at...
if ( false === strpos( $url, $_SERVER['REQUEST_URI'] ) ) {
// Then let's redirect.
wp_safe_redirect( $url, 301 );
exit;
}
}
}
add_action( 'template_redirect', 'na_redirect_slug_requests', 10, 50 );
Just remember to replace "events" with your custom post type slug.
本文标签: pluginsHow To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially
版权声明:本文标题:plugins - How To Use htaccess to Rewrite Link Structure for a Page that is Generated Programatcially 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745153720a2645041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论