I am using Apache and mod_rewrite to rewrite Web addresses for my web application. You can observe it here:

RewriteEngine On
RewriteBase / 

# www. to non-www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect non-existant files so there's a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ $1/ [R=301,L]

# Send the URL to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]

All working fine, the main problem may be the trailing slash rewrite. It really works when I am at the bottom from the domain, however in my staging atmosphere I am running this application inside a subdirectory. I am needing to customize the RewriteBase directive to incorporate the subdirectory or even the rewrite fails.

I am searching for an answer which will give a trailing slash towards the URL - no matter if the application is running around the cause of the server, without needing to alter the RewriteBase. Thanks ahead of time.

After poking around plus some help by @MortBM, appears like the below is effective:

RewriteEngine On

# www. to non-www.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Add a trailing slash to any non-existent files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R=301,L]

# Send the URI to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]

Summary: getting rid of the RewriteBase, and taking advantage of %{REQUEST_URI} inside the redirect made it happen :)