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 neededRewriteRule ^/?(signup)/?$ /acc/signup/index.php?a=signUp [NC,L]RewriteRule ^/?(signup)/(process)/?$ /acc/signup/process/index.php [NC,L]#signIn - Again, not always neededRewriteRule ^/?(signin)/?$ /acc/signin/index.php?a=signIn [NC,L]RewriteRule ^/?(signin)/(process)/?$ /acc/signin/process/index.php [NC,L]#signOut - Again, not always neededRewriteRule ^/?(signout)/?$ /acc/signout/index.php [NC,L]# These are the only two that a front end user will use# category/subCategoryRewriteRule ^/?([a-z-]+)/([a-z0-9-]+)/?$ /display/index.php?t=$1&s=$2 [NC,L]# categoryRewriteRule ^/?([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.How can I do something like:If (URL Starts with '/mod/' then send it to the '/moderator/' folder where the RewriteRules there will apply) orIf (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 administratorHow can I achieve this?
RewriteRule to send all URLs with `mod` in them to the `moderator` directory
htaccess;apache;mod rewrite;url rewriting
Your root .htaccess should look like this:# Mod RewriteRules, some 12 in all RewriteRule ^mod/(.*)$ /moderator/$1 [NC,L]RewriteRule ^signup/(.*)$ /acc/signup/$1 [NC,L]RewriteRule ^signin/(.*)$ /acc/signin/$1 [NC,L]RewriteRule ^signout/(.*)$ /acc/signout/$1 [NC,L]# These are the only two that a front end user will use# category/subCategoryRewriteRule ^/?([a-z-]+)/([a-z0-9-]+)/?$ /display/index.php?t=$1&s=$2 [NC,L]# categoryRewriteRule ^/?([a-z-]+)/?$ /display/index.php?t=$1 [NC,L]Moderator folder's .htaccess:RewriteRule ^(all|new|edit|redo|reject)/push/?$ index.php?mode=$1&push=0 [NC,L]RewriteRule ^(all|new|edit|redo|reject)/?$ index.php?mode=$1 [NC,L]Signup folder's .htaccess:RewriteRule ^$ index.php?a=signUp [NC,L]RewriteRule ^process/?$ process/index.php [NC,L]SignIn folder's .htaccess:RewriteRule ^$ index.php?a=signIn [NC,L]RewriteRule ^process/?$ process/index.php [NC,L]SignOut folder's .htaccess:RewriteRule ^$ index.php [NC,L]EditThese rules will match URL's like /signup or /signup/ or /signup/some.RewriteCond %{REQUEST_URI} ^/mod$ [OR]RewriteCond %{REQUEST_URI} ^/mod/.*RewriteRule ^mod(.*)$ /moderator$1 [NC,L]RewriteCond %{REQUEST_URI} ^/signup$ [OR]RewriteCond %{REQUEST_URI} ^/signup/.*RewriteRule ^signup(.*)$ /acc/signup$1 [NC,L]RewriteCond %{REQUEST_URI} ^/signin$ [OR]RewriteCond %{REQUEST_URI} ^/signin/.*    RewriteRule ^signin(.*)$ /acc/signin$1 [NC,L]RewriteCond %{REQUEST_URI} ^/signout$ [OR]RewriteCond %{REQUEST_URI} ^/signout/.*    RewriteRule ^signout(.*)$ /acc/signout$1 [NC,L]