I have the following working. It essentially will pull in content from a sub folder if it exists without displaying the subfolder in the url. The sub folder is /content
If a request comes in for example.com/foo/test and the folder /content/foo/test/ exists it will render the content for the requested URL. So the URL will remain what it is even though content is rendering from a subdirectory.
This is great. How do I have it map requests / to the index.htm file in the /content directory without actually changing the url also?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
# Remove trailing slash on any URL that is requested directly (excludes rewritten URLs)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule (.*)/$ /$1 [R=301,L]
# If request maps to a directory in "/content" then rewrite and append trailing slash
RewriteCond %{DOCUMENT_ROOT}/content/$1 -d
RewriteRule ^([^.] )$ content/$1/ [L]
CodePudding user response:
You can include another "unconditional" rule before the last rule to rewrite requests from /
to content/
- no need for any filesystem checks. For example:
# Rewrite root
RewriteRule ^$ content/ [L]
# If request maps to a directory in "/content" then....
: