Rewrite a suffixed url
-
Greetings!
So.. I’m trying to do something that’s strange and probably ill advised. I have a custom post type, product, and I’m trying to add another method of reaching the product single page. Here’s what I’ve got:
`
function add_product_buy_rewrite($wp_rewrite) {
$wp_rewrite->rules[‘([^/]+)/buy/?$’]= ‘index.php?product=$matches[1]’;
return $wp_rewrite;
}
`
The structure would be /product-name/buy. Presently there’s really three pages:
1. The single: /product/product-name
2. The archive: /product/
3. The Overview: /product-name/The overview is a page that provides information, faq, etc. for the product. The product single is the page wherein the user can add it to their cart. The goal is to make /product-name/buy the single product page, and canonize the new url to avoid seo issues.
Unfortunately, the code above does not work. I can see the rule in the rules, but when I attempt to go to a page using that url, I get a 404. Admittedly I’m pretty new to rewrites, and it’s a bit of a black magic, so any direction/advice on this would be greatly appreciated.
Thanks!
- The topic ‘Rewrite a suffixed url’ is closed to new replies.