Question

This is my .htaccess rule:

RewriteRule ^([a-zA-Z0-9\.]+)/([0-9\.]+)/(.*)/(.*)$ m.pl?id=$1&cv=$2&cu=$3&qty=$4

So, a link like cpa/11/axg/4 gets redirected correctly.

But if the 3rd value is blank, i.e.

cpa/11//4, it does not get redirected to the rule defined above.

I am not sure how to address this.

Était-ce utile?

La solution 2

Since the third parameter is optional, solved it as follows:

RewriteRule ^([a-zA-Z0-9\.]+)/([0-9\.]+)/?(.*)/(.*)$ m.pl?id=$1&cv=$2&cu=$3&qty=$4

Autres conseils

You can have 2 separate rules to address this:

RewriteRule ^([a-zA-Z0-9.]+)/([0-9.]+)/([0-9]+)/?$ m.pl?id=$1&cv=$2&qty=$3 [L,QSA]

RewriteRule ^([a-zA-Z0-9.]+)/([0-9.]+)/([^/]+)/([^/]+)/?$ m.pl?id=$1&cv=$2&cu=$3&qty=$4 [L,QSA]
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top