在.htaccess文件中重写URL [英] URL rewrite in .htaccess file

查看:78
本文介绍了在.htaccess文件中重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的.htaccess文件有两个问题.以下脚本有效,但有局限性

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

限制::如果adid大于10,则失败.我希望它还有任何数量的数字并可以工作.我当前的解决方案是每次id超出范围时都添加此代码.

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.

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

Problem Two. Mapping multiple $_GET variables.

说我有一个这样的网址

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

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

非常感谢您的时间

推荐答案

第一个问题:

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

这篇关于在.htaccess文件中重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆