HtAccess:基本 ModRewrite

发布于 2024-08-26 01:19:20 字数 303 浏览 1 评论 0原文

给定这样的网址:

mysite.com/index.php 
mysite.com/page/member/lobby.php 
mysite.com/page/videos/video1.php

如何使用 .htaccess 重写网址以隐藏 /page/ 文件夹(当它存在时)?

所以最终的结果是:

mysite.com/index.php
mysite.com/member/lobby.php
mysite.com/videos/video1.php

Given urls like this:

mysite.com/index.php 
mysite.com/page/member/lobby.php 
mysite.com/page/videos/video1.php

How can I rewrite the urls with .htaccess to hide the /page/ folder when it's present?

So the end result is:

mysite.com/index.php
mysite.com/member/lobby.php
mysite.com/videos/video1.php

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

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

发布评论

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

评论(1

无声情话 2024-09-02 01:19:20

您可以使用此规则将 page/ 添加到内部路径:

RewriteCond $1 !=page
RewriteRule ^([^/]+)/.+ page/$0 [L]

现在,每个 URI 路径请求都至少有两个路径段,但第一个段不是 page 将是前缀与/page。因此 /member/lobby.php 将被重写为 /page/member/lobby.php

You can use this rule to add page/ to your path internally:

RewriteCond $1 !=page
RewriteRule ^([^/]+)/.+ page/$0 [L]

Now every request that’s URI path has at least two path segments but that’s first segment is not page will be prefixes with /page. So /member/lobby.php will be rewritten to /page/member/lobby.php.

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