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
# 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/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) 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
How can I achieve this?
RewriteRulewill match on every request. But you have a valid reason, you don't want all of them together, let me post an answer and lets see if that will work for you.