简体   繁体   中英

htaccess site/category/name/page error

I have a url in my site with pagination, like this:

http://localhost/category/food/1

category = to call category.php
food = is ONE category, may have any name
1 = is the page number

The problem is, maybe I have page number, maybe not. If I don't have a page number I want just to send page 1 to php.

I tried:

RewriteRule ^category/(.*) /category.php?categoria=$1
RewriteRule ^category/(.*)/(.*) /category.php?categoria=$1&id=$1

To sum up, I want to access my page in two different ways:

http://localhost/category/food - in this case send 1 to php
or
http://localhost/category/food/1

what is wrong in my code that it is not working?

Have your rules as this:

Options -MultiViews
RewriteEngine On

RewriteRule ^category/([\w-]+)/(\d+)/?$ category.php?categoria=$1&id=$2 [L,QSA,NC]

RewriteRule ^category/([\w-]+)/?$ category.php?categoria=$1&id=1 [L,QSA,NC]

Avoid using .* as it matches everything in regex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM