Htaccess does not correctly validate the redirect rule

0

It has in htaccess where regex works perfectly with no numbers in the rule, but with numbers not working correctly.

RewriteRule ^([a-zA-Z]{1,20})-to-([a-zA-Z]{1,20})-([a-zA-Z0-9-]{1,30})\/?$ page.php?ti=$1&at=$2&pl=$3 [NC,L]//linha anterior
RewriteRule ^([a-zA-Z]{1,20})-to-([a-zA-Z]{1,20})-([a-zA-Z0-9-]{1,30})-([0-9]{1,3})\/?$ page.php?ti=$1&at=$2&pl=$3&pagination=$4 [NC,L]

The previous line is the page and the second line is the page with pagination. if the third rule, both on the first and second lines, is a-zA-Z- (with the last one at the end) everything works fine, but if it is a-zA-Z0-9- it does not work as it should.

the page URL looks something like this:

www.exemplo.com/bla-to-ble-nome-com-numero-2

page url with pagination

www.exemplo.com/bla-to-ble-nome-com-numero-2-3

nome-com-numero-2 refers to part 3 of the regex

    
asked by anonymous 07.04.2016 / 05:21

1 answer

1

The reason is that it is not falling on rule 2 and rather on rule 1.

Look closely at ([a-zA-Z0-9-]{1,30}) this section looks exactly like nome-com-numero-2-3

In order to solve this problem, you must change the order of the rule, since you are going from the most specific to the least specific.

RewriteRule ^([a-zA-Z]{1,20})-to-([a-zA-Z]{1,20})-([a-zA-Z0-9-]{1,30})-([0-9]{1,3})\/?$ page.php?ti=$1&at=$2&pl=$3&pagination=$4 [NC,L] // regra mais especifica
RewriteRule ^([a-zA-Z]{1,20})-to-([a-zA-Z]{1,20})-([a-zA-Z0-9-]{1,30})\/?$ page.php?ti=$1&at=$2&pl=$3 [NC,L]// regra menos especifica
    
07.04.2016 / 05:34