My directory is as follows:
root/
├── index.php
├── about.php
├── privacy.php
└── about/
├── brand.php
└── history.php
I would like that when the user types meusite.com/about
, HTACCESS redirects it to the about.php
file. However, if the user types meusite.com/about/
, HTACCESS should use the folder by accessing the files contained in that directory.
It would be the trailing slash that will define whether the URL will go to a directory or a file.
Is it possible to do this?
EDIT 2
I was able to make the URLs default - that is, with a slash always at the end of them - and at the same time, return the correct page by removing the .php
extension.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301]
RewriteRule ^about/brand/$ /about/brand.php [NC,L]
The drug is having to add everything manual. But I'm still looking for a better result.