使用 mod_rewrite 将路径转换为查询字符串变量

发布于 2024-12-17 13:02:05 字数 364 浏览 0 评论 0原文

我正在尝试让 Apache 发送:
http://mydomain.com/这些/are/arguments/mmmk

至:
http://mydomain.com/?pages=这些/are/arguments/mmmk

这样 $_GET['pages'] 将显示 这些/are/参数/mmmk

我已将“AllowEncodedSlashes”设置为“开”。

该规则需要能够处理尾部斜杠,并且当没有子页面(例如 http://mydomain.com)时,

有人知道如何完成此任务吗?

I am trying to make Apache send:
http://mydomain.com/these/are/arguments/mmmk

to:
http://mydomain.com/?pages=these/are/arguments/mmmk

Such that $_GET['pages'] will display these/are/arguments/mmmk.

I have set 'AllowEncodedSlashes' to On.

The rule needs to be able to handle trailing slashes, and when there is no subpages (like http://mydomain.com)

Does anyone know how to accomplish this task?

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

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

发布评论

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

评论(1

墨小沫ゞ 2024-12-24 13:02:05

为了不重写图像/脚本,您需要首先确保 .htaccess 文件中不存在该文件或目录

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  # Rewrite everything else through the pages parameter 
  RewriteRule ^(.+)$ /?pages=$1 [L] 

In order to not rewrite images/scripts you'll need to make sure the file or directory does not exist first in your .htaccess file

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  # Rewrite everything else through the pages parameter 
  RewriteRule ^(.+)$ /?pages=$1 [L] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文