如何在一个RewriteRule中将/foo重写为index.php?x=foo,同时将/foo/bar重写为index.php?x=foo&bar=true?

发布于 2024-09-11 19:47:06 字数 612 浏览 2 评论 0原文

使用 Apache 的 RewriteEngine,如何将 /foo 重写为 index.php?x=foo 但将 /foo/bar 重写为 index.php?x=foo php?x=foo&bar=true 在一个 RewriteRule 中?

我现在有这个:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)? index.php?x=$1 [L,NC] # rewrites /foo to index.php?x=foo, but not /foo/bar to index.php?x=foo&bar=true

这只将 /foo 重写为 index.php?x=foo,但不将 /foo/bar 重写为 index.php?x=foo&bar=true。如何将其添加到 RewriteRule 中?

Using Apache's RewriteEngine, how to rewrite /foo to index.php?x=foo but rewrite /foo/bar to index.php?x=foo&bar=true in one RewriteRule?

I have this now:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)? index.php?x=$1 [L,NC] # rewrites /foo to index.php?x=foo, but not /foo/bar to index.php?x=foo&bar=true

This only rewrites /foo to index.php?x=foo, but not /foo/bar to index.php?x=foo&bar=true. How can I add that to the RewriteRule?

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

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

发布评论

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

评论(1

删除→记忆 2024-09-18 19:47:06

尝试这些规则:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)$ index.php?x=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?x=$1&$2=true [L]

第一个规则是如果请求的 URI 可以映射到现有文件或目录则破坏。否则,如果其他两个规则之一与请求的 URI 路径匹配,则测试并应用其他两个规则。

Try these rules:

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)$ index.php?x=$1 [L]
RewriteRule ^([^/]+)/([^/]+)$ index.php?x=$1&$2=true [L]

The first rule is to break if the requested URI can be mapped to an existing file or directory. Otherwise the other two rules are tested and applied if one of them matches the requested URI path.

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