htaccess 重定向到文件夹

发布于 2024-09-14 09:43:51 字数 890 浏览 10 评论 0原文

我不确定标题应该是什么,但它的概念很简单,但我对 .htaccess 重写毫无用处。

我目前有:

RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1

它将很乐意将所有请求发送到我的索引,我可以做我想做的事。

我有:

RewriteRule ^events/([a-zA-Z0-9-./]+)/?$ index.php?page=events/index&id=$1

对于更多间歇性的东西..

但我想说

如果网址是“/mycms/...”将使用发送到%{HTTP_HOST}/cms并留在那里...

任何人都可以帮助?我的“包罗万象”规则总是把事情搞砸。


编辑我让它工作得很好

RewriteRule ^mycms([a-zA-Z0-9-./]+)?$ /cms$1 [L]

RewriteCond %{REQUEST_URI} !^/cms 
RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1

现在我写http:// /localhost/mycms 并将前往 http://localhost/cms

我仍然想屏蔽 '/cms/' 文件夹... o_O

I wasn't sure what the title should be but its s simple concept but I'm useless with .htaccess rewrites.

I currently have:

RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1

which will happily send all requests to my index and I can do what I want.

I have:

RewriteRule ^events/([a-zA-Z0-9-./]+)/?$ index.php?page=events/index&id=$1

For more intermit stuff..

But I want to say

If the url is "/mycms/..." Send use to %{HTTP_HOST}/cms and stay there...

Can anyone help? my 'catch all' rule keeps fecking it up.


Edit I Got this to work wonderful

RewriteRule ^mycms([a-zA-Z0-9-./]+)?$ /cms$1 [L]

RewriteCond %{REQUEST_URI} !^/cms 
RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1

Now I write http://localhost/mycms and will head off to http://localhost/cms

I still want to mask the '/cms/' folder though... o_O

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

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

发布评论

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

评论(1

五里雾 2024-09-21 09:43:51

您只需要在 catch all 之前进行重写,并使用 L 标志来防止它再次被重写,这样的事情就足够了。

RewriteRule ^events/([a-zA-Z0-9-./]+)/?$ index.php?page=events/index&id=$1 [L]
RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1

You just need to place a rewrite before your catch all and use the L flag to prevent it being rewritten again, something like this should suffice.

RewriteRule ^events/([a-zA-Z0-9-./]+)/?$ index.php?page=events/index&id=$1 [L]
RewriteRule ^([a-zA-z0-9_-]+)/?$ index.php?page=$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文