Try something like this:
DirectoryIndex index.php
Options -MultiViews
RewriteEngine On
RewriteRule ^admin(?:$|/([^.]*))$ admin.php?uri=$1 [QSA,L]
RewriteRule ^([^.]+)$ index.php?uri=$1 [QSA,L]
This does assume that none of your URLs (that need rewriting) contain dots (.
). This avoids the need for a filesystem check to make sure the request does not map to a static resource, that would normally include a file extension (delimited by a dot).
MultiViews
needs to be disabled (if not already) since you are requesting a URL /admin
that is the basename of the file you are rewriting to. If MultiViews was enabled then /admin.php
would be called without the URL parameter.
The QSA
(Query String Append) flag is only required if you are expecting a query string on the original request, that would need to be appended to the rewritten URL.
A request for the document root (homepage) will call index.php
without the uri
parameter.
Aside: Just a note on terminology...
If the URL takes ANY OTHER parameter (other than /admin
)
What you are calling "parameter" here is really the URL-path (or path-segments). URL Parameters are the name=value pairs in the query string (what you are wanting to rewrite the request to).
In your example, you are rewriting the URL-path to a URL parameter value.