1

I coded a webpage. At all sites I have to include several files via HTML. These files are stylesheets, images, javascripts and so on.

My big problem is Firefox. If I open the main page (https://www.example.de/) in any browser everything works fine. If I open a subpage (https://www.example.de/sub_page) of the webpage in Microsoft Edge, Chrome, Safari and a few other browsers everything displays as it should. Only in Firefox the subpage completly displays incorrect. Over the network tab I found out that these files are not loaded, because Firefox uses wrong urls for the files I have to include.

For example:
Included JS:

<script src="./scripts/main.js"></script>   

Expected example-URL (Used URL in all other browsers):
https://www.example.de/scripts/main.js
Used example-URL only by Firefox:
https://www.example.de/subpage/scripts/main.js
And that last one is a wrong url. The first one is correct.

The subpage file is in the same directory as the main site file and the main site file loads perfectly in Firefox with the same include-urls. So why only in Firefox the urls get like this at my subpage? Any help is highly appreciated. Please tell me if you need more examples or anything else.

EDIT:
The subpage is a single php file and not in a extra folder. .htaccess edits the urls on the whole site. It is looking like this:

RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [NC,L]

ErrorDocument 400 ./404.php

Best regards,
Filip.

Filip Degenhart
  • 631
  • 4
  • 19
  • Experienced the same issue. Found no solution. – mc.b Jun 13 '22 at 19:37
  • Are you able to use / instead of ./ ? – Geat Jun 13 '22 at 20:04
  • This needs more details. Is `sub_page` supposed to be an existing file or folder, or did you use URL rewriting to "create" that? If the latter, show how please. – CBroe Jun 14 '22 at 06:27
  • @Geat Changed all urls to / instead of ./. Unfortunately same problem. – Filip Degenhart Jun 14 '22 at 10:35
  • @CBroe I added more information under the edit section. Hope it helps. – Filip Degenhart Jun 14 '22 at 10:35
  • Are you sure, in Firefox you are on `https://www.example.de/sub_page`, and not `https://www.example.de/sub_page/`? Your RewriteRule to add the `.php` suffix allows for an optional trailing slash, but in that case the base URL used to complete relative ones, would of course be different in terms of "folder depths." – CBroe Jun 14 '22 at 11:01
  • Using root-relative URLs for such assets - so the path from the domain root, starting with a leading `/` - solves such problems in the IMHO easiest & best way. (Using a `base` element would be another alternative, but somehow I never managed to grow fond of that one in particular :-) ) – CBroe Jun 14 '22 at 11:03
  • @CBroe Oh, found out that `https://www.example.de/sub_page` works. `https://www.example.de/sub_page/` does not work. Can I somehow code something which redirects users if they call the wrong url? So if they call `https://www.example.de/sub_page/` that I redirect them to `https://www.example.de/sub_page` automatically? – Filip Degenhart Jun 14 '22 at 12:37
  • https://stackoverflow.com/questions/70442408/remove-trailing-slash-with-htaccess – CBroe Jun 14 '22 at 12:43

0 Answers0