Skip Navigation

[Resolved] URL param as subfolder

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 3 voices.

Last updated by Minesh 2 years, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2280179

Let's say I have a post type "highschool" and I have a url structure for them like:
/highschool/hs1
/highschool/hs2
, etc.

I want to add some functionality like course booking but due to SEO/cache and other reason I don't what to use URL params like ?applyto=true but use URL structure like:

/highschool/hs1/applyto
/highschool/hs2/applyto

I try to use url rewrite like this:

add_action( 'init', 'add_booking_rules' );
function add_booking_rules() {
add_rewrite_rule(
'highschool/([^/]+)/applyto/?$',
'index.php?highschool=$matches[1]&applyto=true',
'top');

}

but then I go ti URL /highschool/hs1/applyto it is just redirected me to /highschool/hs1/

so, as you use rewrite rules to handle custom posts it will be great if you could advise me what is wrong with my approach.

#2280481

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

I'm sorry, but in support we don't have any special insight into custom rewrite rules.

We can point you towards where to add simple rewrite rules in the settings for the post type, or direct you towards WordPress documentation about implementing rewrites, but we can't come up with custom rewrite rules for you.

The main reference for rewrite rules is at: https://developer.wordpress.org/apis/handbook/rewrite/

I've found this guide helpful myself, although there are many more guides available when searching:
hidden link

#2280583

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

In addition to that, if you would like, you can add the plugin that offers such pretty permalink structure:
- https://wordpress.org/plugins/permalink-manager/
- https://wordpress.org/plugins/custom-permalinks/
- https://wordpress.org/plugins/custom-post-type-permalinks/

You can use any of the plugin that suits best as per your requirement.

#2280707

Thanks a lot for your help.

The question is not about rewrite rules in general - I find and use some references also.
The question is about how you process it in Toolset.
To be clear - if I will make this rules for the page, like

/pageforapplication/hs1/
/pageforapplication/hs2/

there hs1 and hs2 just a slug for Highschool custom posts

then they processed correctly with rewrite rule and I have no issues.

But if I want to add redirect rule as an extension after custom post like

/highschool/hs1/applyto
/highschool/hs2/applyto

then it just redirect me to the post itself to URLs:

/highschool/hs1/
/highschool/hs2/

Thats why I suppose this is not the problem of url rewrite, but the problem of how it combined with Toolset rewrites or rewriten URL processed within Toolset

#2280731

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Toolset do not offer such custom rewrite mechanism.

If you disable the Toolset and then try to register the post type using WordPress core function register_post_type() to create custom post type and then you add the rewrite code you shared you will have the same result. Its not on Toolset.

It will require custom code or you should be know how to deal with such custom rewrite rules. If you require custom programming for your project, please feel free to contact our certified partners:
- https://toolset.com/contractors/