mod_rewrite if file exists

前端 未结 2 797
你的背包
你的背包 2020-12-19 14:42

I already have two rewrite rules that work correctly for now but some more code has to be added to work perfectly.

I have a website hosted at mydomain.com and all su

相关标签:
2条回答
  • 2020-12-19 15:10

    Thanks to Gumbo I managed to figure out how to fix it. Here is what I came up with:

    #GET FILE FROM THE SUBDOMAIN DIRECTORY IF IT EXISTS
    RewriteCond $1 !^subs/
    RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^.]+)\.clan-websites\.com(.*)$
    RewriteCond %{DOCUMENT_ROOT}/subs/%1/%2 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/subs/%1/%2 -d
    RewriteRule ^(.*)$ subs/%1%2 [L]
    
    #GET THE DEFAULT FILE IF NOT FOUND IN SUBDOMAIN
    RewriteCond $1 !^subs/
    RewriteCond %{REQUEST_URI} ^(.*)$
    RewriteCond %{DOCUMENT_ROOT}/subs/factory/%1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/subs/factory/%1 -d
    RewriteRule ^(.*)$ subs/factory%1 [L]
    
    #SEND THE DATA TO THE SUBDOMAIN CMSMS SINCE NO FILE EXISTS
    RewriteCond $1 !^subs/
    RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^.]+)\.clan-websites\.com(.*)$
    RewriteCond %{DOCUMENT_ROOT}/subs/%1/%2 !-f [OR]
    RewriteCond %{DOCUMENT_ROOT}/subs/%1/%2 !-d
    RewriteRule ^(.*)$ subs/%1/index.php?page=$1 [L]
    
    0 讨论(0)
  • 2020-12-19 15:15

    The problem is that you need to provide the absolute file system path to get -f and -d working. If you’re in the document root, you can use this rule:

    RewriteCond $1 !^subs/
    RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -d
    RewriteRule ^(.*)$ subs/default/$1 [L]
    

    But if you’re somewhere else, it’s going to be hard to get the right path prefix.

    0 讨论(0)
提交回复
热议问题