0

I am creating a one page application. When the user changes the url, or reloads, anything after "mysite.com/" is sent as a variable to ajax the requested subdirectory content (e.g. /users/me)

This code works great when the relative url has only one "sub-directory". But sub-sub-directories, and even simply "sub-directory/", receive errors and load no content.

  • mysite.com/sub_directory -------------------------- navigates to mysite.com/index.html
  • mysite.com/sub_directory/ ------------------------- throws error
  • mysite.com/sub_directory/sub-sub-directory --- throws error

Resource interpreted as Stylesheet but transferred with MIME type text/html: "mysite.com/all/default.css"
Resource interpreted as Script but transferred with MIME type text/html: "mysite.com/all/jquery.js"


htaccess attempt: redirect anything after "mysite.com/" to index.html.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.html [L]


Additional info:
.* and (^/?.$) and (^./$)* and .*/ etc. produce the same results
including the AddType rules for .css and .js files seems to do nothing.
The htaccess file sits in the same folder as index.html

Is this a regex problem? Usually when there is a problem with the htaccess code, the server responds with a 500 internal server error, but in this case no content is loaded and the above error is thrown.

UPDATE: I have a bunch of scripts that are in a "scripts" folder, which is on the same directory-level as index.html and .htaccess. They all load without error, perhaps the problem is that .htaccess is not applying to the files in its own directory-level?


cheesetaco
  • 721
  • 1
  • 6
  • 11

1 Answers1

0

Fixed: Okay so I got it working. The client would hang because it could not find the jquery and css files I had referenced. I'm thinking what happened is when the server read and loaded the index.html, it hit the lines

<script src="default.css"></script> 
<script src="jquery.js"></script>

and since they were not hard references to their file locations, they were not found and htaccess rerouted the request back to index.html, which continues in a loop to infinitum causing the browser to hang.

simply changing all 'real' file references to non-relative links fixes the problem

e.g.

<script src="http://www.mysite.com/default.css"></script>

silly that that was the solution, but I guess problems can be hard because the answer is too simple to notice

cheesetaco
  • 721
  • 1
  • 6
  • 11
  • If you leave out http: it will take the script with the current protocol, so either http or https. Eg – Lexib0y Feb 11 '22 at 10:25