.htaccess 重写规则帮助
我的 index.html 中有一个链接:
href="my_page.php?cat=14&p=1";
现在,我怎样才能重写它,使其看起来像这样:
/my_page/14/1
到目前为止我已经有了这个,但我不知道如何将结尾“/1”添加到此:
RewriteRule ^kategori/([0-9_]+)$ browse_cat.php?cat_gr=$1 [NC]
谢谢
I have a link in my index.html:
href="my_page.php?cat=14&p=1";
Now, how can I rewrite this so that it looks like this:
/my_page/14/1
I have this so far, but I don't know how to add the ending '/1' to this:
RewriteRule ^kategori/([0-9_]+)$ browse_cat.php?cat_gr=$1 [NC]
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
家里没有安装 apache,但这应该可以解决问题。
(?:...)?使第二部分可选。所以 /kategori/14 和 /kategori/14/1 应该可以工作。
如果没有,你需要两条规则
Have no apache installed here at home, but this should do the trick.
(?: ...)? makes the second part optional. So /kategori/14 as well as /kategori/14/1 should work.
If not, you'll need two rules
仅当至少指定了 cat 和 p 时,这才有效。
This would only work if both cat and p at a minimum are specified.
如果您实际上使用的是
/my_page.php?cat=14&p=1
之类的 URL,并希望它们“显示”为/my_page/14/1
,您将需要两条规则:一条将/my_page.php?cat=14&p=1
从外部重定向到/my_page/14/1
,一条重写/my_page/14/1
内部到/my_page.php?cat=14&p=1
。请注意,此规则仅适用于该特定 URL(数字和顺序或参数)。更通用的规则会变得更复杂;在这种情况下,使用 PHP 等高级语言可能更容易。
此外,如果您已经在 HTML 文档中使用“正确”的 URL,而不是将每个请求重定向/重写两次,那就更好了。
If you’re actually using URLs like
/my_page.php?cat=14&p=1
and want them to be “displayed” as/my_page/14/1
, you will need two rules: One to redirect/my_page.php?cat=14&p=1
externally to/my_page/14/1
and one to rewrite/my_page/14/1
internally to/my_page.php?cat=14&p=1
.Note that this rule does only work with this specific URL (number and order or parameters). A more general rule will get more complex; using a higher level language like PHP is probably easier in this case.
Furthermore, it would be better if you already use the “right” URL in your HTML documents rather than redirecting/rewriting every request twice.