Accessing file in parent directory of folder containing index file
21:56 22 Oct 2023

The directory is like so: htdocs

  • public

    • index.php
  • welcome.php

The 'public' folder is set as the document root, so that incoming requests go to index.php. The index.php checks to see if the user is authenticated, and if not it has a redirect to send them to the welcome page.

header("Location: welcome.php");

However, I keep getting a 404 error, despite the URL displaying the correct file path.

Any thoughts? Here's what I've tried.

header("Location: /welcome.php");
header("Location: ./welcome.php");
header("Location: ../welcome.php");

.htaccess

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

^The above created too many redirects.

Placing the index.php file in the same folder as welcome.php works fine but I'm trying to organize my web app and can't do that if I have to keep everything at or below the index.php file.

php apache http-redirect web-applications http-headers