-2

I'm using a subdomain but want to use the images, scripts and php files from the primary domain.

I'm getting a Loading Failed error in Firefox Developer for both of the following "src":

 <script src="https://www.example.com/php/scripttest2.js"></script>
 <script src="../php/scripttest2.js"></script>

bst365体育投注网址大全I'm really hoping there is a universal/single solve that addresses all of the below. I'd like to avoid duplicating assets/files as much as possible.

File structures:

bst365体育投注网址大全primary: domain.com

  • /images
  • /js
  • /php
  • main.css

bst365体育投注网址大全subdomain: my.domain.com

  • index.php

Question 1: Is the following PHP safe?

bst365体育投注网址大全I've been able to load the php scripts from the subdomain index.php file via: "../php/test1.php";

  1. seemed like I needed a CORS header for the PHP files. Turns out I didn't require this as the "include" worked without the Access-Control-Allow-Origin header.

Question 2: How can I load the IMAGES and CSS w/out an absolute URL?

I haven't been able to get images and CSS to load using a relative path (I can using absolute URL".

Question 3: how to load javascript files?

Question 4: If I load a javascript file that has an AJAX call, will the path in the AJAX script need to be changed?

This js file path is from the primary domain and references another php file on the primary domain.

  • How is this Java related? – Mordechai Jul 1 at 5:32
  • 1
    “seemed like I needed a CORS header for the PHP files. Turns out I didn't require this as the "include" worked without the Access-Control-Allow-Origin header.” - CORS applies to HTTP requests made by a browser. You are not making requests using a browser here, you are not even making an HTTP request to begin with - you are making an include via the file system. (With your question 4 CORS might come into play again though.) – CBroe Jul 1 at 8:03
  • 1
    “How can I load the IMAGES and CSS w/out an absolute URL?” - you can’t. You want to load content from a different domain here, so you need to mention that domain in your URLs. A relative URL always resolves against the current URL of the main document. – CBroe Jul 1 at 8:05