I am trying to map.htaccess to /books
or /books/
or /books/<url_slug>
:
Options All -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1 [R=301,L]
# Map /books/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^books$ book.php [NC,L,QSA]
Result:
book.php:
<?php
echo '<h1>Books</h1>';
?>
2
Answers
Solved yesterday.
You are just making your life more complicated.
The general advice is to avoid use of url-rewrites for specifying paths. Instead you should just have something like:
And use
$_SERVER['REQUEST_URI']
on the PHP side to then route the incoming call.