Site in a subfolder without CSS and images or with a 403, what is wrong

When a site in a subfolder doesn't load its CSS, images or scripts, the cause is almost always the paths inside the files, which point to the root of the domain instead of the subfolder. A static HTML site needs no special server configuration, so the cause usually lies in the paths or in the file names. A 403 Forbidden usually means that index.html is missing or that a rule in the main site's .htaccess also applies to the subfolder. The cleanest solution is to upload the site to its own subdomain.

Find which file doesn't load

Before you change anything, see exactly what fails, using your browser's developer tools (DevTools).

  1. Open the page in Chrome, Edge or Firefox.
  2. Press F12 (on a Mac Cmd + Option + I) and go to the Network tab.
  3. Reload the page with Ctrl + F5 (on a Mac Cmd + Shift + R).
  4. Look at the rows shown in red and at the Status column.
  5. Click one of them and see the full address the page requested.

What the code means:

  • 404. The file was not found at the requested address. The path or the file name is wrong.
  • 403. The file or folder exists, but access is forbidden. See the causes below.

Why CSS doesn't load in a subfolder

Say you uploaded the site to public_html/promo/, so it opens at example.gr/promo/. In HTML, the path to a file can be written in two ways.

In the HTML Where the browser looks Result
/css/style.css example.gr/css/style.css Looks in the root of the main site, not in promo. Doesn't load.
css/style.css example.gr/promo/css/style.css Looks next to the page. Loads.

The leading slash makes the path absolute, meaning it starts from the root of the domain. Without the slash you have a relative path in the HTML, which starts from the page's folder. The difference between relative and absolute paths explains most "css not loading" cases. A site built to run at the root of a domain usually has absolute paths, which is why in a subfolder it loses its styling and images.

To fix it:

  1. Open the HTML and CSS files with cPanel > Files > File Manager or on your computer.
  2. Find the paths that start with / in href, src and inside the url(...) entries of the CSS.
  3. Make them relative. /css/style.css becomes css/style.css, and from a page in a deeper folder ../css/style.css.
  4. Also check full addresses, such as https://dokimi.example.gr/img/logo.png. If they point to the old place where the site used to run, change them.
  5. Upload the files again and reload the page with Ctrl + F5.

Inside CSS files, relative paths start from the CSS file's folder, not the page's. If style.css is in promo/css/ and the images are in promo/img/, the path inside the CSS is ../img/eikona.jpg.

The file name must match exactly

The server distinguishes uppercase from lowercase. Logo.PNG and logo.png are two different files, even though on your Windows or Mac computer they may have looked the same. If the page asks for logo.png and the file is called Logo.PNG, you will get a 404. Also avoid spaces, accents and Greek characters in names. See which characters to avoid in file names.

Why it returns 403 Forbidden

The index file is missing. When you open the address of a folder, for example example.gr/promo/, the server looks for the folder's directory index, meaning an index.html or index.php file. If there isn't one and directory listing is turned off, you get a 403. Rename the home page to index.html, in lowercase. For folder listing, see cPanel Indexes.

A rule in the main site's .htaccess. The rules in the .htaccess file in public_html apply to all subfolders. Security plugins and main site settings often block access to certain file types or folders. To check the .htaccess in relation to the subfolder:

  1. Open File Manager and click Settings.
  2. Tick Show Hidden Files (dotfiles) and click Save.
  3. Open the .htaccess file in public_html and look for lines with Deny, Require all denied, RewriteRule with [F], or rules for file extensions.
  4. Before you change anything, download a copy of the file.

If you don't know what a rule does, don't delete it, because it may be protecting the main site. Prefer the subdomain solution below.

File permissions. Files should have 644 permissions and folders 755. In File Manager, select the file, click Permissions in the toolbar, correct the permissions in the window that opens and click Change Permissions.

A server security rule. If the 403 appears only on a specific action, for example when submitting a form, ModSecurity may have stopped it. In that case open a ticket with the page address and the time the error appeared.

If instead of a 403 you see a window asking for a username and password, the folder or one of its parent folders is password protected with Directory Privacy.

Subdomain or subfolder, which is better

A micro-site or a promotional page works more smoothly on its own subdomain, for example promo.example.gr. It has its own folder, it isn't affected by the main site's .htaccess, and absolute paths work just as they did when the site was built.

Create the subdomain from cPanel > Domains > Domains, without the Share document root option, so that it gets its own folder. Then upload the site's files to the new folder. You will find detailed steps in how to create a subdomain in cPanel. Check in SSL/TLS Status that the subdomain has an active free SSL certificate.

Frequently Asked Questions

The page opens but the CSS doesn't load and I see plain text. What is wrong?
The CSS file is not loading. In the Network tab, check the address it requests. It usually starts with / and looks in the root of the domain instead of the subfolder.

The site works fine on my computer but not on the server. Why?
On your computer you open the files from your own disk, where paths and names behave differently. On the server, what matters is where the folder sits within the domain and whether the names match exactly, including uppercase and lowercase.

I open the address of a file directly and get 403 forbidden. What do I do?
If you are opening a folder, put an index.html file in it. If you are opening a file, check the permissions and the .htaccess file in public_html, as described above.

Can the subfolder break my main site?
A static site in a subfolder does not affect the main site. However, if you delete or change rules in the .htaccess file in public_html, you may affect the main site as well. That is why a subdomain is safer.

I fixed the paths and still see the same thing. Why?
The browser may be keeping the old result. Press Ctrl + F5 or open the page in a private window.

What do I send Konet if I can't find the cause?
Open a ticket with the page address, the folder where you uploaded the files and a screenshot of the Network tab showing the files that fail.

Was this article helpful?

Related service Konet Web Hosting cPanel, LiteSpeed and automatic backups: 24 every 2 hours for 48 hours, then 6 daily, 4 weekly and 3 monthly.