Does anyone know how to change the URL for all php files inside a subfolder of the root directory and also remove .php?
http://localhost/pages/x.php
to
http://localhost/x
Example:
http://localhost/pages/example.php
to
http://localhost/example
You can do it like this, which only executes if the request exists in pages and doesn't exist in root. So existing items in root don't get rewritten.
RewriteEngine on
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/$1 !-f
RewriteCond %{CONTEXT_DOCUMENT_ROOT}/pages/$1.php -f
RewriteRule ^([^/]+)$ pages/$1.php