Can I do an if/then/else in htaccess?

后端 未结 5 799
名媛妹妹
名媛妹妹 2020-12-19 07:42

I have a site that serves up certain content based on the subdomain. So it is the same set of files, and maybe the header and some info in the site pages changes based on t

5条回答
  •  失恋的感觉
    2020-12-19 08:09

    If it were me (and I haven't thought to do this before) I would:

    1. Use an internal redirect using mod_rewrite to different site roots (/suba or /subb) depending on some factors (emulating IF/ELSE)
    2. Use symlinks on the public directory, but not the .htaccess

    so:

    /sites/subdomain_a/.htaccess
    /sites/subdomain_a/pub
    /sites/subdomain_b/.htaccess
    /sites/subdomain_b/pub
    

    where

    /sites/subdomain_a/pub == /sites/subdomain_b/pub
    

    using

    ln -s
    

    or similar. Then use mod_rewrite to redirect (internally) to the right site root. I think mod_rewrite is run before .htaccess is loaded.

    This means you are effectively serving the same site files with a different .htaccess depending on the subdomain.

    Hope this helps, bit of a hack.

    Would be interested to see if something better exists.

提交回复
热议问题