I need to prevent second directory depth or deeper placed strings from matching first directory depth rules with multi-domain support thrown in for extra chaos. Besides this issue everything is working fine. I need to make some clarifications first.
The page having trouble is when I have the string ‘blog’ (without the quotes) in the URL at dir2 or deeper though I only want it to match dir1.
Visual of directory depth…
localhost/example.com/dir1/dir2/dir3/
I have multi-domain support, essentially multiple websites share the same modules (modules being blog/, forums/, messages/, etc). Each site has it’s directory in the same directory as the modules (/dir1/website1/ is in the same directory as dir1/blog/). Essentially either you visit a set module (blog/, forums/, messages/) which are rewritten to or if a module does not match it gets rewritten to the main index file.
What is happening is that…
admin/templates/blog
…is matching…
blog/
I have tried using the ^starts with operator though the problem is that due to the multi-domain support I have to transverse two directories to begin with.
Here is my current code…
RewriteEngine on
RewriteRule .*/admin(.+) admin$1 [QSA]
RewriteRule .*/blog(.+) blog$1 [QSA]
RewriteCond %{REQUEST_URI} !.*(admin/|blog/)
RewriteRule !\.(css|js)$ index.php
I can remove the blog/ condition on the second to last line however the blog module ends up rewriting to index.php. I’ve done some tweaking for the past few hours without any success and unfortunately multi-domain support is a non-existent issue online as far as I can tell.
I know this is a tricky setup and I’ll try to clarify any questions anyone has.
As far as I understand, instead of the too generic
.*match at the start of your RewriteRules you should try to match the multi-domain strings.So let’s try something like that:
Where
[^/]means anything which is not “/“, and^[^/]*/foomeans start with anything that is not a slash several times until you reach slash and then foo. So this should be an efficient way to detect ‘foo’ as being only a first level directory name, as ‘/‘ is not allowed in a domain name.