I want to pass first directory as a variable and subdirectory as another variable.
It works when for urls with both directories (/something/something2) but I get an error 404 when I try with only one (/something).
RewriteRule ([^/]+)/([^/]+) /posts/?category2=$1&category2=$2 [L,QSA]
How can I pass only category1 when category2 isn’t available?
Few solutions:
Multiple rules (easier to understand but a bit slower):
Single rule:
Here the second part of URL (/something2) is optional. Please note — $2 was changed to $3.