Friendly URL with variable parameter

2

I have the following regular expression for Friendly URL:

RewriteRule ^categoria/([a-z0-9-]+)/([a-z0-9-]+)/([a-z0-9-]+)/?$ categoria.php?idc=$1&nome=$2&pg=$3 [NC]

I would like to leave the 3 parameter, pg, optional, have or have not. The way I'm using it is mandatory to provide the 3 parameter.

    
asked by anonymous 14.05.2016 / 19:39

1 answer

2

Did you try this?

RewriteRule ^categoria\/([a-z0-9-]+)\/([a-z0-9-]+)(\/([a-z0-9-]+))?\/?$ categoria.php?idc=$1&nome=$2&pg=$4 [NC]

So you put one group inside the other and make the parent parameter optional by including the slash. In the response variable, you just skip the parent parameter ($ 3) until you find the child parameter ($ 4).

    
10.10.2016 / 21:08