Q:

Make shortened and long urls play together on the same domain (RewriteRule)

Long story short, I want to have both example.com/aJ5 and example.com/any-other-url working together.
I'm using apache and not very good at writing regex.
I have already a global RewriteRule which sends everything to the app entry point.
What I need is to tell apache if length($path) is <= 5 chars then rewrite to another location.
I know I can use {1,5} like syntax in regex, but don't really know if it's what I'm looking for.
I'd like to implement this at web-server level rather than php level. Any help is appreciated.

A:

If you can assume that the - character will not be included in short URLs:
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9]){1,5} 
RewriteRule ^ /app-entry-point?url=%1 [L]

This is untested but something like this should work. Essentially you're passing a condition if REQUEST_URI is something like /abc12, control switches to whatever handler you want. It will skip URLs over 5 characters or that include the 'slug' character "-" or an underscore.
%1, the last RewriteCond backreference, will be expanded to the short URL. Put this above your other rules to enforce this first -- with the [L] flag it will stop rewriting URLs and pass control to the app.

