.htaccess 文件中的 URL 重写

发布于 2024-09-17 21:23:37 字数 815 浏览 5 评论 0原文

我当前的 .htaccess 有两个问题。下面的脚本可以工作,但有一个限制

RewriteRule ^products/([0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9])/$ /viewad.php?adid=$1

限制:如果 adid 大于 10。它会失败。我希望它有任何数量仍然存在并且可以工作。我当前的解决方案是每次 id 高于范围时添加此内容。

RewriteRule ^products/([0-9][0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9][0-9])/$ /viewad.php?adid=$1 

有人可以完善或解释如何纠正这一规则以使数字超出范围吗?

问题二。 映射多个 $_GET 变量。

假设我有一个像这样的网址,

http://veepiz.com/africanews.php?app=view&func=viewcategory&categoryid=2&page=1

我会编写什么规则来使其采用这种格式。

http://veepiz.com/africanews/category/2/page/1

http://veepiz.com/africanews/2/1

非常感谢您的宝贵时间

I have two problems in my current .htaccess. The script below works but has a limitation

RewriteRule ^products/([0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9])/$ /viewad.php?adid=$1

Limitation: if adid, is more than 10. it fails. I want it to have whatever number still there and work. my current solution was to add this everytime the id went higher than range.

RewriteRule ^products/([0-9][0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9][0-9])/$ /viewad.php?adid=$1 

Could some one refine or explain how to correct this rule to take numbers out of range.

Problem Two.
Mapping multiple $_GET variables.

say i had a url like this

http://veepiz.com/africanews.php?app=view&func=viewcategory&categoryid=2&page=1

what rule would i write to have it in this format.

http://veepiz.com/africanews/category/2/page/1

or

http://veepiz.com/africanews/2/1

Thanx a lot for your time

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

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

发布评论

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

评论(2

习ぎ惯性依靠 2024-09-24 21:23:37

第一个问题:

RewriteRule ^products/([0-9]+)$ /products/$1/ [R]
RewriteRule ^products/([0-9]+)/$ /viewad.php?adid=$1

或者更好:

RewriteRule ^products/(\d+)/?$ /viewad.php?adid=$1

问题二:

RewriteRule ^africanews/(\d+)/(\d+)$ /africanews.php?app=view&func=viewcategory&categoryid=$1&page=$2

First problem:

RewriteRule ^products/([0-9]+)$ /products/$1/ [R]
RewriteRule ^products/([0-9]+)/$ /viewad.php?adid=$1

Or better yet:

RewriteRule ^products/(\d+)/?$ /viewad.php?adid=$1

Problem Two:

RewriteRule ^africanews/(\d+)/(\d+)$ /africanews.php?app=view&func=viewcategory&categoryid=$1&page=$2
蓝海 2024-09-24 21:23:37

这解决了问题 2(感谢 aularon):

RewriteRule ^africanews/(\d+)/(\d+)$ /africanews/$1/$2/ [R]
RewriteRule ^africanews/(\d+)/(\d+)/$ /africanews.php?app=view&func=viewcategory&categoryid=$1&page=$2

This fixes problem 2 (thanks to aularon):

RewriteRule ^africanews/(\d+)/(\d+)$ /africanews/$1/$2/ [R]
RewriteRule ^africanews/(\d+)/(\d+)/$ /africanews.php?app=view&func=viewcategory&categoryid=$1&page=$2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文