简体   繁体   中英

URL Rewriting in Wordpress htaccess

I've built a Wordpress site that has a product page which retrieves product info from an external system using the querystring id passed in. So www.domain.com/product/?id=n loads the Wordpress product page which then loads the product info using the id.

This works fine.

However, I want to rewrite this URL so that:

www.domain.com/product/productname/id retrieves www.domain.com/product/?id=n

When I add the following to htaccess, the page returns a 404 because it doesn't exist in Wordpress.

RewriteRule ^product/productname/(.*)$ ^product/?id=$1 [L]

Does anyone know how to write this rule in such a way that it doesn't get hijacked by Wordpress rewriting?

After doing some additional searching, I've found some links that may help you get started. The secret lies in WordPress's add_rewrite_rules hook. Haven't tried these myself yet, but looks promising:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM