简体   繁体   中英

.htaccess subdomains and common files

I have a file structure that serves mutliple domains with a top level .htaccess pushing requests down to the domain specific directories:

...

ReWriteCond %{REQUEST_URI} !webroot/domains/www.sitea.com/

ReWriteRule ^(.*)$ webroot/domains/www.sitea.com/$1 [L]

ReWriteCond %{REQUEST_URI} !webroot/domains/www.siteb.com/

ReWriteRule ^(.*)$ webroot/domains/www.siteb.com/$1 [L]

...

An .htaccess at the domain level (eg webroot/domains/www.siteb.com/.htaccess) then applies various rules to manage the URLs for the domain pages:

...

DirectoryIndex pageincludes/home.php

RewriteRule ^home$ pageincludes/home.php [L]

...

So the file structure looks something like this :

/webroot/domains/www.sitea.com/

/webroot/domains/www.siteb.com/

/webroot/js/script1.js

/webroot/images/image1.png

My problem is that I want to be able to use common resources in the served pages eg:

<script type="text/javascript" src="/js/script1.js"></script> <img src="/images/image1.png" alt="80%"></img>

These resources are not found by the client. Is this pattern a non-starter or is there a way I can get this to work?

Many thanks.

I would just add symbolic links on the file system. Trying to do rewrite rules is kinda complicated and your apache server will have to process them over and over again for every page. Not so for a symbolic link.

Ex:

ln /webroot/js /webroot/domains/www.sitea.com/js

The way you have it structured now the requests are rewritten so they cannot see the files in the js or images directories.

I'm assuming you want the shared resources to make updates easier, and that's certainly doable (although a better serverfault question). If you place an alias to the directories in your domain folders (and apache is configured to follow aliases) you should be fine.

Could you add an additional condition to each domain, so as not to rewrite requests for these shared resources. eg

ReWriteCond %{REQUEST_URI} !^(js|images)

Or how about using a separate domain for the shared resources?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM