地图请求 /要从子文件夹显示内容
我有以下工作。本质上,如果它存在而无需在URL中显示子文件夹,则它将从子文件夹中提取内容。 sub文件夹是/content,
如果请求输入示例,请com.com/foo/test,并且文件夹/content/foo/test/存在,它将为请求的URL渲染内容。因此,即使内容正在从子目录中呈现,即使内容正在呈现,URL仍将是它的原样。
这很棒。我如何将其映射为 / content目录中的index.htm文件,而不实际更改URL?
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]
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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在之前在之前将另一个“无条件”规则在
/
重写content> content/
的最后一个规则之前 - 无需任何文件系统检查。例如:You can include another "unconditional" rule before the last rule to rewrite requests from
/
tocontent/
- no need for any filesystem checks. For example: