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.

Was it helpful?

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

OTHER TIPS

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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top