1
votes

After rewriting all my url rules, everything that is passed is treated as a rewrite rule this results in no 404 pages ever! How can I serve 404 pages for pages that are not found i.e. example.com/books is url rewritten which is fine. However example.com/dfersfn isnt but this is also served and 404 is sent. Heres the content from my htaccess:

RewriteEngine on
RewriteRule \.(css|jpe?g|gif|png|js|ico|svg)$ - [L]
RewriteCond %{REQUEST_URI} "/f1/" [OR]
RewriteCond %{REQUEST_URI} "/f2/" [OR]
RewriteCond %{REQUEST_URI} "/f3/"
RewriteRule (.*) $1 [L]
RewriteCond %{REQUEST_FILENAME} !-d  
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ book.php?slug=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/(.*)/? read.php?slug=$1&cslug=$2 [NC,L]
1

1 Answers

1
votes

You need to do this in your book.php and read.php scripts. When you check for the "slug" and "cslug" in the database or whatever, if they don't exist, have the script itself return a 404 via:

header('HTTP/1.0 404 Not Found');

THere's more info in this SO question: Why won't my PHP app send a 404 error?