如果你正在建设新的客户关系管理系统,那么,现在就开始就能够把静态资产储存在网络根基上,以及你在网根之外的图书馆。 仅保留网络根基中的指数.php。
因此,这首先给这 tree树:
path/
-to/
-cms/
-www/
-index.php
-static
-js/ /* cms shared js */
-css/ /* cms shared css */
-images/ /* cms shared images */
-lib/
-cms.php /*lots of php files related to the cms*/
现在,你希望在同一厘米处内处理几个网站,并隐藏固定资源的网站名称。 牵头2个问题:
- why handling several websites with the same cms installation, deploying the cms several time, one for each website is usually better, IMHO. But anyway, why not.
- why hiding the site name on the static resource url?
就第二个问题而言,我只能看到这样做的原因之一,它有助于优化这些资产的切身政策。 您要说,www.example1.com/static/images/foo.png
与www.example2.com/static/images/foo.png
相同。 精心配置的反向代理可以做到这一点。 但是,良好的分数还可以处理共享静态资源的共同领域,例如:cdn.example.com/static/commd/images/foo.png
。
Now you are maybe actually having ugly url like: http://www.example2.com/cms/www.examples2.com/static/images/foo.png
. And yes this is quite ugly, simply because you could try to check some static assets from example1.com while browsing example2.com, by altering the link manually. So someone could send an url http://www.seriouswebsite.com/static/images/adultcontent.com/foo.png
claiming that seriouswebsite.com is storing some ugly picture, simply because adultcontent.com is handled in the same server with the same cms. Now that s something not very important, done in other cms, like in Drupal multidomain default managment for example. I assume you have this situation, that you do not want, and you would like it to be handled by an url in this form : http://www.example2.com/images/foo.png
.
www.un.org/Depts/DGACM/index_spanish.htm 关于与PHP
因此,现在你们的多层树种是:
path/
-to/
-cms/
-www/
-index.php
-static
-js/ /* cms shared js */
-css/ /* cms shared css */
-images/ /* cms shared images */
-domain1.com/
-static
-js/
-css/
-images/
-domain2.net/
-static
-js/
-css/
-images/
-lib/
-cms.php /*lots of php files related to the cms*/
解决办法之一是固定内容的改写规则,先用域名确定静态ur,但你将减少装载共同资产的可能性。 如果具体领域的资源与地方一样具有关键词,那么你仍然可以这样做。
因此:
# private image
/path/to/cms/www/domain1.com/static/images/foo.png => http://domain1.com/static/local/images/foo.png
# shared by the cms
/path/to/cms/www/static/images/foo.png => http://domain1.com/static/images/foo.png
沉积规则现在必须探测static/ local部分并改写到static/domain1.com。 现行领域为领域1.com。 与此类似(未测试):
RewriteRule ^static/local/(.*)$ %{HTTP_HOST}/static/$1 [QSA,L]
这一解决办法增加了几个限制:
- You should have a dedicated virtualHost (better) or rewriteRule (for .htaccess fallbacks) rewritting all alternate domain name access to a canonical domain name for handled domains. It s also better for SEO. as
http://domain1.com/static/images/foo.png
will be ok but not http://www.domain1.com/static/images/foo.png
or http://foo.domain1.com/static/images/foo.png
, and http://DOmaiN1.com/static/images/foo.png
should be checked.
- The subdirectory storing assets must be named exactly like the HHTP_HOST, no liberty on that.
- this rule does not prevent usage of
domain1.com/static/images/foo.png
direclty, so users could still build bad links, some other rewriteRule with 301 redirects could be added.