URL rewrite in .htaccess file

2019-08-08 20:23发布

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

2条回答
女痞
2楼-- · 2019-08-08 20:42

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
查看更多
Root(大扎)
3楼-- · 2019-08-08 20:42

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
查看更多
登录 后发表回答