GRoups priority
-
Hi!
is there any way to order the groups by priorities just like the priorities of the rules within the groups?
Are the groups loaded in alphabetical order?regards
-
Hi!
There is a position column in the wp_redirection_groups table, but it is not queried at request time for all matching URLs.
with just adding a joing and order by that position wil order all the rules following the groups order.
I mean:
file: plugins/redirection/models/redirect/redirect.php
function: get_for_matched_urlchange:
SELECT * FROM {$wpdb->prefix}redirection_items WHERE match_url=%s OR match_url='regex'
to
SELECT {$wpdb->prefix}redirection_items.*, {$wpdb->prefix}redirection_groups.position FROM {$wpdb->prefix}redirection_items JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_items.group_id = {$wpdb->prefix}redirection_groups.id WHERE match_url=%s OR match_url='regex' ORDER BY {$wpdb->prefix}redirection_groups.position asc
-
This reply was modified 4 years, 4 months ago by
gonza.ar.
public static function get_for_matched_url( $url ) { global $wpdb; $url = new Red_Url_Match( $url ); $sql = "SELECT {$wpdb->prefix}redirection_items.*, {$wpdb->prefix}redirection_groups.position FROM {$wpdb->prefix}redirection_items JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_items.group_id = {$wpdb->prefix}redirection_groups.id WHERE match_url=%s OR match_url='regex' ORDER BY {$wpdb->prefix}redirection_groups.position asc"; $rows = $wpdb->get_results( $wpdb->prepare( $sql, $url->get_url() ) ); $items = array(); if ( count( $rows ) > 0 ) { foreach ( $rows as $row ) { $items[] = new Red_Item( $row ); } } usort( $items, array( 'Red_Item', 'sort_urls' ) ); return $items; }
There is no group priority. They are loaded in the order on the groups page, or alphabetical.
The priority column in the groups table is deprecated and will be removed.
Hi John,
The problem is that it is difficult to follow the position of the rules when we have a lot. For example. we have 45 groups and 40 rules in each one. If we need to add a rule that needs to be validated before another rule, it will be difficult to find the position of the rules with similar matches, and it will also be difficult to reposition them.
is there any way that the plugin solves it in another way?
REgardsI don’t know what kind of rules you are trying to create, but it does sounds like it is very complex, and will be complex regardless of group positioning. I would look into trying to simplify the rules. Generally the position is used for the exceptions, not for the majority, and it suggests to me that there is maybe a better way.
Hi John,
Thanks for the reply, yes, we have complex rules and these rules follow priorities.
Is there a hook that allows me to alter the response ?Regards
Alter what response?
John,
The responose of the function “get_for_matched_url”
I would like to know if there is a hook after the function that does that query to organize the response of possible all redirects that match the URL.Regards
There are WordPress filters you can use to modify database queries, but nothing in Redirection.
I would strongly suggest looking into a simpler solution. Maybe if you can give an example of your situation then there may be an easier alternative.
Hi,
Here is an example:
We have 40 groups with 30 rules each.
In the last group (Z) we have the following rule in the position 20 :“^(?i)test(.*)/?$” “/” [R=301,L]
we have in the second group (B) the following rule in the position 30:
“^testguest/?$” “https://test.com/test” [R=301,L]
For the plugin, the rule of the group Z will be first because was created first, but we don’t want that. Of course I can just change the position of the rule in the second group to 19, and then the plugin will take the rule of the group B first.
The problem is that we have 1200 rules, and every day we add and remove rules, will be hard to follow the position of the rules.For this reason I think that having orders in the groups, in addition to the orders of the rules within the groups, would be a great functionality.
Regards
Priority does not need to be unique across every redirect. It only needs to enable whatever small set of stacked redirects to work. For example, your Z rule could be priority 100000, and it will always be last.
-
This reply was modified 4 years, 4 months ago by
- The topic ‘GRoups priority’ is closed to new replies.