RewriteRule splits the last character of the parameter
P粉081360775
P粉081360775 2024-01-10 18:12:07
0
1
423

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?

P粉081360775
P粉081360775

reply all(1)
P粉541796322

Your regular expression pattern is incorrect due to the use of the quantifier and the optional / in between.

You can use this rule:

RewriteRule ^produktas/([\w-]+)(?:/([\w-]+))?/?$ produktas?slug=&var= [NC,L,QSA]
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!