mod_rewrite send all URLs with `mod` to the `moderator` directory

I have a .htaccess file in the root directory of my project, that contains all the rewrite rules for the site to functions. Most of these rules belong to the mod section of the site, and only two of them belong to the front end, which the users use.

Problem is, when a front end user uses the site, apache ends up matching all the rules including the ones for the mods and signup etc, until it reaches the one for the end user, which I feel is unnecessary. I’ve checked this in the .htaccess log.

# Mod RewriteRules, some 12 in all
RewriteRule ^/?(mod)/(all|new|edit|redo|reject)/(push)/?$ /moderator/index.php?mode=$2&push=0 [NC,L]
RewriteRule ^/?(mod)/(all|new|edit|redo|reject)/?$ /moderator/index.php?mode=$2 [NC,L]

#signUp - Again, not always needed
RewriteRule ^/?(signup)/?$ /acc/signup/index.php?a=signUp [NC,L]
RewriteRule ^/?(signup)/(process)/?$ /acc/signup/process/index.php [NC,L]

#signIn - Again, not always needed
RewriteRule ^/?(signin)/?$ /acc/signin/index.php?a=signIn [NC,L]
RewriteRule ^/?(signin)/(process)/?$ /acc/signin/process/index.php [NC,L]

#signOut - Again, not always needed
RewriteRule ^/?(signout)/?$ /acc/signout/index.php [NC,L]

# These are the only two that a front end user will use
# category/subCategory
RewriteRule ^/?([a-z-]+)/([a-z0-9-]+)/?$ /display/index.php?t=$1&s=$2 [NC,L]

# category
RewriteRule ^/?([a-z-]+)/?$ /display/index.php?t=$1 [NC,L]

If you look at the above rules, the last two are the only ones that a user using the front end will use. However, the cannot be placed on top, because they’ll end up catching anything first, because of the way they are.

Can I place all rules for the moderator, signup and signin in their own directories, and do a rewrite rule in the root .htaccess file, that when it detects a url with mod, like /mod/all will send that request to the moderator directory. That way the root .htaccess file will have only the last two rules for the front end user along with others like no hot linking ones.

Something like:

If (URL Starts with '/mod/' then send it to the '/moderator/' folder where the RewriteRules there will apply) or
If (URL Starts with '/signup/' then send it to the '/acc/' folder where the RewriteRules there will apply)

and so on.
My directory structure is as follows:

/acc/ ...handles account login and creation
/display/ ... handles front end display
/moderator/ ...the sites administrator

Any help will be appriciated :slight_smile:

So this is strictly a performance issue? For regular users, you don’t want the mod and signup rewrites to run at all?

The first thing I would suggest is running some benchmarks (Apache comes with a benchmarking tool) so that you’ll know how fast things are running both before and after any changes. This will tell you whether you’ve succeeded and how much faster you’ve made things. Or you may also discover that the most performance you could possibly squeeze out isn’t enough to bother worrying about. In fact, I strongly suspect this will be the case. Probably the most you can expect to gain is a few microseconds.