mod_rewrite RewriteCond 和查询字符串

发布于 2024-09-07 18:29:23 字数 543 浏览 4 评论 0原文

最近,我一直在为客户做一个小项目。我正在考虑使用 WordPress 风格的漂亮 URL 格式。我在 google 上搜索了很多,发现了 Apache 的 mod_rewrite 和 RewriteRuleRewriteCond。但没有找到任何可以处理随机参数的示例。例如:

  • /index.php?param=1/index/param/1
  • /index.php?foo=bar&hour=1&mins= 12/index/foo/bar/hour/1/mins/12
  • /index.php?page=login&attempt=2/index/page/login/attempt/2

或类似的内容。

正如您所看到的,参数不是固定的。有办法实现这个目标吗?任何帮助将不胜感激。

谢谢

recently, I have been working on a small project for a client. I was thinking about using a wordpress style pretty URL format. I googled around a lot and came accross Apache’s mod_rewrite and RewriteRule, RewriteCond. But didn't find any example which can handle random of parameters. For example:

  • /index.php?param=1/index/param/1
  • /index.php?foo=bar&hour=1&minutes=12/index/foo/bar/hour/1/minutes/12
  • /index.php?page=login&attempt=2/index/page/login/attempt/2

or something similar.

As you can see parameters are not fixed. Is there anyway to achieve this? Any help would be greatly appreciate.

Thanks

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

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

发布评论

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

评论(1

拍不死你 2024-09-14 18:29:23

大多数 CMS 使用 PHP 来完成此操作。

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

PHP

$URI = substr($_SERVER['REQUEST_URI'], 1);
$URIparts = explode("/", $URI);

然后你就得到了 url 各部分的数组,你可以根据需要处理它们。

Most CMS does this with PHP.

.htaccess

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

PHP

$URI = substr($_SERVER['REQUEST_URI'], 1);
$URIparts = explode("/", $URI);

Then you've got an array of the parts of the url, and you can process them as you want.

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