地图请求 /要从子文件夹显示内容

发布于 2025-01-24 04:34:29 字数 643 浏览 2 评论 0原文

我有以下工作。本质上,如果它存在而无需在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾铮苏瑾 2025-01-31 04:34:29

您可以在之前在之前将另一个“无条件”规则/重写content> content/的最后一个规则之前 - 无需任何文件系统检查。例如:

# Rewrite root
RewriteRule ^$ content/ [L]

# If request maps to a directory in "/content" then....
:

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....
:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文