URL使用的.htaccess和Apache两个参数重写)重写、参数、两个、URL

2023-09-02 11:40:26 作者:水果味的可可

我有下面的.htaccess code:

I have below code in .htaccess:

Options -Indexes

RewriteEngine on

RewriteRule ^category/([a-zA-Z0-9-/]+)/page/([0-9]+)/{0,1}$ themes/tema_2/category.php?slug=$1&page=$2 [NC,L,QSA]

我有问题,第二个参数页......当我做 $ _ GET ['塞'] 我得到了这样的事情: fudbal /页/ 2 如果我的网址是这样的: http://exmpl.com/category/fudbal/page/2

I have problem with second parameter "page"... When I do $_GET['slug'] i got something like this: fudbal/page/2 if my url is like this: http://exmpl.com/category/fudbal/page/2.

所以 $ _ GET ['塞'] 返回所有在类别/ 像它的蛞蝓。

So $_GET['slug'] returns all after category/ like it's slug.

我要做到这一点:当我回声 $ _ GET ['塞'] 来呼应 fudbal 键,当我赞同 $ _ GET ['页'] 来呼应 2

I need to achieve this: When I echo $_GET['slug'] to echo fudbal and When I echo $_GET['page'] to echo 2.

推荐答案

您需要调整您的正则表达式来解决这样您的问题:

You need to tweak your regex to fix your issue like this:

Options -Indexes
RewriteEngine on

RewriteRule ^category/([^/]+)/?$ themes/tema_2/category.php?slug=$1 [NC,L,QSA]
RewriteRule ^category/([^/]+)/page/(d+)/?$ themes/tema_2/category.php?slug=$1&page=$2 [NC,L,QSA]
 
精彩推荐
图片推荐