Static files from a subdomain

Developer
Từ Hungary
Thành viên kể từ thg 7 2017

Hello!

I want to invoke all static files from a subdomain. I don't want a cdn service, just a subdomain.
Eg static.yourdomain.com

I tried to invite this:
<? php include vmod :: check (FS_DIR_APP. 'includes / boxes / box_region.inc.php'); ?>

<? php include 'https://static.yourdomain.com/includes/boxes/box_region.inc.php'); ?>

But it doesn't work. Is there a solution for this?

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim

Your code has syntax errors. But you can't include a remote file over the HTTP protocol. Use the server side file system path instead.
This will not work because that file requires app_header to be executed first.

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim

Are you looking for a solution to load images etc from a static subdomain?

Developer
Từ Hungary
Thành viên kể từ thg 7 2017

Yes Tim, I want to solve this.

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim
  1. Create a subdomain that works as an alias domain for your website.

  2. Try this vQmod:


<modification>
 <id>Static Domain</id>
 <version>1.0</version>
 <vqmver required="true">2.4.0</vqmver>
 <author>litecart.net</author>
  <file name="includes/library/lib_document.inc.php">
    <operation error="log">
      <search position="before"><![CDATA[
      if (class_exists('stats', false)) {
      ]]></search>
      <add><![CDATA[
    // Static Domain
      if (substr($_SERVER['REQUEST_URI'], 0, strlen(WS_DIR_ADMIN)) != WS_DIR_ADMIN) {
        $static_domain = 'https://static.mydomain.com';
        $GLOBALS['output'] = preg_replace('#("|\(|\'| )(https?://'. preg_quote($_SERVER['HTTP_HOST'], '#') .')?(/[^"\'\) ]+\.(a?png|css|eot|gif|jpe?g|js|less|map|otf|svg|tiff|ttf|woff2?)(\?[^\'\)"]+)?)("|\)|\'| )#', '$1'. rtrim($static_domain, '/') .'$3$6', $GLOBALS['output']);
      }
      ]]></add>
    </operation>
  </file>
</modification>```

3. Put this in your .htaccess

```    # Deny access to non-static content
    RewriteCond %{HTTP_HOST} ^static\.
    RewriteCond %{REQUEST_URI} !\.(a?png|css|eot|gif|jpe?g|js|less|map|otf|svg|tiff|ttf|woff2?)$ [NC]
    RewriteRule ^ - [R=403,L]```

And

```    # Allow cross domain access to fonts
    <IfModule mod_headers.c>
      <FilesMatch "\.(eot|ttf|otf|woff2?)$">
        Header set Access-Control-Allow-Origin "*"
      </FilesMatch>
    </IfModule>```
Developer
Từ Hungary
Thành viên kể từ thg 7 2017

Hi Tim!

Thank you very much for inviting everything from the static domain.
Only the fontawesome icons do not appear anywhere.

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim

This means there could be a CORS issue.
Are you on nginx or apache? .htaccess is for apache

Developer
Từ Hungary
Thành viên kể từ thg 7 2017

I use a Litespeed web server that handles .htaccess modifications.

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim

What does your browser console say?

tim
Founder
Từ Sweden
Thành viên kể từ thg 5 2013
tim

So static.domain.com should be replaced by the domain you have in mind. Did you go for the modification here in the forum thread or the add-on?

Chủ đề này đã bị đóng do không hoạt động trong thời gian dài. Không thể đăng bài vào chủ đề này.
This website uses no cookies and no third party tracking technology. We think we can do better than others and really think about your privacy.