I am having an issue with my .htaccess / .php files I set up my web project in a way that it's split into 3 levels:
- base level (mywebsite.com)
- pages (mywebsite.com/news)
- subpages/articles (mywebsite.com/news/123)
And all three are working as expected, here's my .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&sub=$2 [L]
I have to admit, I am not very good with the Regular Expressions for .htaccess/mod_rewrite as it is something I have done very rarely up to this point.
However my issue now is, that people dont get sent to a 404 error page if the page id (see $1) is not valid, like people can technically enter mywebsite.com/asdasdasd/ and it'll bring them (obviously) to the index.php, now my question is, can this be done some way in the .htaccess or should I just use php to check if the id they entered is valid or not? I did see that there's a thing called rewriteMap but I dont want to change the httpd.conf
Can anyone help?