简体   繁体   中英

Wordpress URL Rewriting and permalinks

I have a problem with rewriting URLS in Wordpress.

On my site I have 2 page templates, one overview page which is listing restaurants, and a detail page for the restaurant itself.

I have the permalinks working for the CPT of the restaurant overviewpage, which is domain.com/restaurants/

I also managed to got the categories in the CPT "restaurants" working ( domain.com/restaurants/category/ ) These are all the templates for the overview page.

However The detail page is ofcourse a different page with a different template, which links to domain.com/restaurant (without the s)

for the detail page I'm currently linking as following:

 domain.com/restaurant?id=[ID]

however this also works

pagename=restaurant&taxonomy_name=[taxonomy]&id=[ID]

Now comes the problem I would like the url to be like domain.com/restaurants/taxonomy_name/restaurant-name/

As you can see it will go through the page restaurants and not restaurant (the individual restaurant page template)

This is what I currenlty have in my functions.php:

function add_restaurant_rewrite() {
       add_rewrite_tag("/%restaurant-categories%/", '([^/]*)');
       add_rewrite_tag("/%postname%/", '([^/]*)');
       add_rewrite_rule('^restoranlar/([^/]*)/([^/]*)/[^/]*)', 'index.php?pagename=restoran&taxonomy_name=$matches[1]&id=$matches[2]', 'top');
}
add_action( 'init', 'add_restaurant_rewrite' );

Is this possible? and how can I achieve this, I've been searching for an answer the past 3 days without any luck and hope someone here can help me.

Thank you

Have you already tried to manually add rules to your .htaccess, like:

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /?pagename=$1&taxonomy_name=$2&id=$3 [L]

Try it yourself at http://www.generateit.net/mod-rewrite/

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