So my .htaccess-file looks like this
<IfModule mod_rewrite.c>
Options +FollowSymLinks - MultiViews
RewriteEngine on
ErrorDocument 404 404.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)$ profile.php?username=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ profile.php?username=$1&page=$2 [L]
</IfModule>
But when I for instance go to 127.0.0.1/random it actually goes to 127.0.0.1/profile.php?username=random which is understandable so that is why I have a piece of code on profile.php to generate a 404 error if the user doesn't exist
if ($User == NULL) { header("HTTP/1.0 404 Not Found"); }
But still it loads the profile and does not go to the 404 error. I have tried with header('Location: index'); and then it redirects to index
What am I missing to get it to generate 404?