Such rewrite can be done like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?_controller=$1&_action=$2 [QSA,L]
It will rewrite (internal redirect) request for /first/second
to /index.php?_controller=first&_action=second
.
It will only work if you requesting non-existing resource. So, if you have such folder /first/second
, then no rewrite will happen.
If you change pattern from ^([^/]+)/([^/]+)$
to ^([^/]+)/([^/]*)$
, then it will also be applicable for this rewrite: /first/
to /index.php?_controller=first&_action=
(notice that trailing slash is required here).
If you change pattern from ^([^/]+)/([^/]+)$
to ^([^/]+)/([^/]+)/?$
, then both /first/second
and /first/second/
(one with trailing slash) will trigger the rule.
If you change pattern from ^([^/]+)/([^/]+)$
to ^([^/]+)(/([^/]*))?$
, then this single rewrite rule will match /first/second
as well as /first/
as well as /first
(obviously, if 2nd segment is not present, then action parameter _action=
will be empty).
It is also possible to make trailing slash with 2 segments optional (i.e. /first/second
and /first/second/
will be treated as the same (from rewriting point of view). For that -- change pattern to ^([^/]+)(/([^/]*))?/?$
.