mod_rewrite 将主机重定向到另一个文件夹

发布于 2024-12-27 21:19:40 字数 453 浏览 1 评论 0原文

我有一些域都重定向到同一个文件夹(我的 public_html)。我想编写一个 .htaccess 文件,将每个域发送到它自己的文件夹(因此不会在导航栏上显示它)。 例如,导航到 http://example.com 将加载文件夹 /public_html/example.com/<我的服务器的 /code>。

在另一个上下文中,我使用了以下代码:

RewriteCond %{HTTP_HOST} example\.com$ [NC,OR]
RewriteRule ^(.*)$ http://www.anotherdomain.com/$1 [R=301,L]

但现在我不想重定向到另一个域;我只想从不同的文件夹中获取文件...

可以实现吗?提前致谢。

I have some domains that all redirect to the same folder (my public_html). I'd like to write an .htaccess file that would send each domain to it's own folder (thus not displaying this on the navigation bar).
For example, navigating to http://example.com would load the folder /public_html/example.com/ of my server.

In another context, I've used this code:

RewriteCond %{HTTP_HOST} example\.com$ [NC,OR]
RewriteRule ^(.*)$ http://www.anotherdomain.com/$1 [R=301,L]

But now I don't want to redirect to another domain; I just want to fetch the files from a different folder...

Is it achievable? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

聚集的泪 2025-01-03 21:19:40

将您拥有的内容替换为:

RewriteCond %{REQUEST_URI} !^/%{HTTP_HOST}/ [NC]
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1  [L]

对于显式主机重定向:

RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} !^/example.com/
RewriteRule ^(.*)$ /example.com/$1  [L]

RewriteCond %{HTTP_HOST} otherexample\.com [NC]
RewriteCond %{REQUEST_URI} !^/abc/otherexample.com/public_html
RewriteRule ^(.*)$ /abc/otherexample.com/public_html/$1  [L]

Replace what you have with:

RewriteCond %{REQUEST_URI} !^/%{HTTP_HOST}/ [NC]
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1  [L]

For explicit host redirects:

RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{REQUEST_URI} !^/example.com/
RewriteRule ^(.*)$ /example.com/$1  [L]

RewriteCond %{HTTP_HOST} otherexample\.com [NC]
RewriteCond %{REQUEST_URI} !^/abc/otherexample.com/public_html
RewriteRule ^(.*)$ /abc/otherexample.com/public_html/$1  [L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文