htaccess 跳过文件夹

发布于 2024-11-10 16:43:33 字数 634 浏览 0 评论 0原文

我到处都看到 htaccess 问题,但我似乎无法让它做我想做的事。我不确定我是否需要重定向或重写。

我正在寻找一种使用子文件夹但使其看起来没有子文件夹的方法。

我的域根目录中有一堆文件夹:

www.mysite.com/folder1
www.mysite.com/folder2
www.mysite.com/folder3
www.mysite.com/folder4

我希望能够将文件夹 1 和文件夹 2 移动到子文件夹,但用户不可以看到该文件夹​​。例如

www.mysite.com/x/folder1
www.mysite.com/x/folder2
www.mysite.com/folder3
www.mysite.com/folder4

,但是用户仍然会看到它原来的样子。

看来我必须使用重定向和重写。如果用户访问 www.mysite.com/folder1,实际上将位于 www.mysite.com/x/folder1 中,而不知道自己位于该子文件夹中。

当然,我需要在不破坏文件夹 4 和文件夹 5 的情况下执行此操作。有想法吗?尖端?技巧?我对 htaccess 不太熟悉

I see htaccess questions all over the place but I cant seem to get the thing to do what I want. Im not sure if a redirect or a rewrite is what I need.

Im looking for a way to use a sub folder but make it look there is not a subfolder.

I have a bunch of folders in the root of my domain:

www.mysite.com/folder1
www.mysite.com/folder2
www.mysite.com/folder3
www.mysite.com/folder4

Id like to be able to move folder1 and folder2 to a subfolder but not have that folder visible to the user. For example

www.mysite.com/x/folder1
www.mysite.com/x/folder2
www.mysite.com/folder3
www.mysite.com/folder4

But the user would still see it as it originally was.

It seems like I would have to use a redirect and a rewrite. If a user goes to www.mysite.com/folder1 the will actually be in www.mysite.com/x/folder1 without knowing that they are in that subfolder.

Of course I need to do this without disrupting folder4 and folder5. Ideas? Tips? Tricks? Im not too familiar with htaccess

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

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

发布评论

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

评论(1

撩发小公举 2024-11-17 16:43:33

这对我有用,也许对其他人有帮助:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1

这告诉服务器忽略公共文件夹,因此当我的 URL 实际上是 mysite.com/public/file 时,它​​会显示并响应 mysite.com/file

This is what worked for me, maybe it will help someone else:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1

This is telling the server to ignore the Public folder, so when my URL is actually mysite.com/public/file it shows and responds to mysite.com/file

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