.htaccess - Mod_rewrite, first rule works perfectly, second rule does not -


i have 2 mod_rewrite rules, defining category , product. products displayed in categories, , clicking on product comes product page:

  1. this works:

http://www.example.com/ele/electricalgoods/ takes code value "ele" , uses rewrite call /view_category.php?cat=ele. works perfectly, using following mod_rewrite:

rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^([^/]*)/([^/]*)/([^/]*)$ /show_category.php?catcode=$1&page=$3 [nc] 

(this includes further "folder" pages in category view such http://www.example.com/ele/electricalgoods/3/)

  1. however, underneath in htaccess file want have similar rewrite so:

http://www.example.com/product/el063/earphones/ rewrites to: /view_product.php?prodid=el063

i did this htaccess code:

rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^product/([^/]*)/([^/]*)$ /show_product.php?prodid=$1 [nc,l] 

but somehow doesn't work expected, want product appear in "product/" folder "/product/<code>/<name>/" layout, , calling /show_product.php file.

what happens call view_product.php page fails 404 error.

i have tried rearrange mod_rewrite rules , have tried variations on escaping / ancasing in brackets product/ segment of url call. have tried changing $1 $2 or $3 incase ordering of codes has changed doesn't appear work.

what doing wrong?

for clarity, here full htaccess code:

options -indexes rewriteengine on  rewritecond %{http_host} !^$ rewritecond %{http_host} !^www\. [nc] rewritecond %{https}s ^on(s)| rewriterule ^ http%1://www.%{http_host}%{request_uri} [r=301]  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^product/([^/]*)/([^/]*)$ /show_product.php?prodid=$1 [nc,l]  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^([^/]*)/([^/]*)/([^/]*)$ /view_category.php?catcode=$1&page=$3 [nc,l] 

edit: updated mod_rewrite code, issue persists l flags , reordering of rules

that's because match first rule ([^/]*)/([^/]*)/([^/]*). because pretty says in combination of 3 directories. need change order. , add l flag @ end stop processing once rule met.

options -indexes rewriteengine on  rewritecond %{http_host} !^$ rewritecond %{http_host} !^www\. [nc] rewritecond %{https}s ^on(s)| rewriterule ^ http%1://www.%{http_host}%{request_uri} [r=301]  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^product/([^/]*)/([^/]*)/?$ /show_product.php?prodid=$1 [nc,l]  rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^([^/]*)/([^/]*)/([^/]*)/?$ /view_category.php?catcode=$1&page=$3 [nc,l] 

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -