The .htaccess file in the root folder:
#
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#
# For contact page .php
RewriteRule ^(contact)$ /$1.php [L]
# Rewrite "/string" to "/cms/string.php"
RewriteCond %{THE_REQUEST} ^GET\ /([A-Za-z0-9_\-]+) [NC]
RewriteRule ^([A-Za-z0-9_\-]+)$ /cms/$1.php [L]
# For 'index'
RewriteCond %{THE_REQUEST} ^GET\ / [NC]
RewriteRule ^$ /cms/index.php [L]
# Rewrite "/cms/string.php" to "/string"...
# ...to prevent viewing of 'physical' file
# Use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ /cms/[^.]+\.php\ HTTP/
RewriteRule ^(cms)/([A-Za-z0-9_\-]+)\.php$ /$2 [R=301,L]
#
This seems to work okay. The URLs are suffixless, eg:
/page
I also have the option for the CMS to exist in a sub-folder and want the same behaviour, eg:
/subfolder/page
I cannot get this to work with:
RewriteBase /subfolder
... when the same .htaccess file is in the subfolder. I've had to add /subfolder to the rules, and even then, some of it won't work properly.
Advice would be appreciated. Essentially I want the CMS to be transportable, either installed in the web root or in a sub-folder.