Here I try to rewrite the parameters in .htaccess and make the last parameter optional:
RewriteRule ^produktas/([0-9a-zA-Z_-]+)/?([0-9a-zA-Z_-]+) /produktas?slug=&var= [NC,L]
So if I type http://site.lt/produktas/the-glass
, then I want to actually get http://site.lt/produktas?slug= the -glass
, but the second parameter var
I want to be empty. But when I run it, I get the first parameter and my $_GET
variable looks like this:
Array ( [slug] => the-glas [var] => s )
If I only enter one parameter, how can I make the first parameter full and the second parameter empty:
http://site.lt/produktas/the-glass
?
Your regular expression pattern is incorrect due to the use of the quantifier
and the optional
/
in between.You can use this rule: