How to manage search result with pagination on .ht

2019-09-09 03:21发布

Here on the application which is developed on php language.

the problem is on pagination, there is three variables(PAGE, refone ,reftow)

not the form will look like:

<from>
   <input type=text name=refone>
   <input type=text name=reftow>
<input type=submit value=search name=search>
</from>

as the user submit search it will result,

for example the -> refone = 1 and reftow = any

in the actual url = ?page=1&refone=1&reftow=%     ... this works
with .htaccess url = ?page/1/1/%                  ... not works

now as there is tow option for search (refone <-> reftow) (refone -> any) (any <- reftow) basically it's working with normal url, but when I use .htaccess for making it short and do not let user to know the exact url job so I use bellow .htaccess for better securing and url management like shortening.

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule . - [L]

RewriteRule ^sref/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+) sref.php?page=$1&refone=$2&reftow=$3 [L,NC] 
RewriteRule ^sref/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+) sref.php?page=$1&refone=$2 [L,NC] 
RewriteRule ^sref/([-a-zA-Z0-9]+)/?$ sref.php?page=$1 [L,NC]

now in case of:

http://m.lhost/web/sref.php?page=1&refone=1&reftow=%
http://m.lhost/web/sref.php?page=1&refone=%&reftow=1
http://m.lhost/web/sref.php?page=1&refone=%&reftow=%

it works and even when I use pagination like page 2,3... it will work but after using the .htacess

http://m.host/web/sref/1/1/%
http://m.host/web/sref/1/%/1
http://m.host/web/sref/1/%/%

here it can not fine the url. Note: here after search, it will use pagination based on search result, which here with out .htaccess working fine but if I use .htacess having problem.

thanks in advance for any kind of advice.

1条回答
相关推荐>>
2楼-- · 2019-09-09 03:56

You must add that % to the list of allowed characters, also your RewriteRule should start with web/sref/...

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule . - [L]

RewriteRule ^web/sref/([A-Za-z0-9_-]+)/([\%A-Za-z0-9_-]+)/([\%A-Za-z0-9_-]+) sref.php?page=$1&refone=$2&reftow=$3 [L,NC] 
RewriteRule ^web/sref/([A-Za-z0-9_-]+)/([\%A-Za-z0-9_-]+) sref.php?page=$1&refone=$2 [L,NC] 
RewriteRule ^web/sref/([-a-zA-Z0-9]+)/?$ sref.php?page=$1 [L,NC]
查看更多
登录 后发表回答