简体   繁体   中英

What Am I Doing Wrong on this HTACCESS file?

Someone please tell me what is wrong with this htaccess rules?

 RewriteCond %{QUERY_STRING} ^q=(.*)&type=downway1$ [NC]
 RewriteRule ^search\.php$  /search\/%1\/1\/? [R=301,NC,L]

 RewriteCond %{QUERY_STRING} ^q=(.*)&type=(.*)$ [NC]
 RewriteRule ^search\.php$  /search\/%1\/%2\/1\/? [R=301,NC,L]

 RewriteRule search/(.*)/(.*)/$  /search.php?q=$1&page=$2 [L] <-- this and
 RewriteRule search/(.*)/(.*)/(.*)/$  /search.php?q=$1&type=$2&page=$3 [L] <-- this 

are not working in same time. for example TYPE = app Q = windows

if I search type by downway1 it works powerfully but if I search in app type Q becomes windows/app not only windows. help me please!

edit: im trying to redirect "search.php?q=someterm&page=1" to "/search/someterm/1/" and "search.php?q=someterm&type=sometype&page=1" to "/search/sometype/someterm/1/"

Rewrite rules are applied in order. In this case, /search/(.*)/(.*)/$ is tested first, and actually does match /search/windows/app/1/ , because the dot operator matches everything, including forward slashes .

Try switching the order of the rules, or, even better, make them order independent by changing (.*) to ([^/]*) , which means match everything, except forward slashes . This will make the first test fail for /search/windows/app/1/ , so apache will move on to the second.

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