2014-06-24 3 views
0

전자 상거래 웹 사이트에서 작업 중이며 URL을 개선하려고합니다. Apache 구성을 활성화 한 다음 .htaccess 파일을 만들었지 만 내 URL은 여전히 ​​동일합니다. 나는 내가 어디로 잘못 가고 있는지 알 수 없다.동적 URL 다시 쓰기

내 URL이 같은 경우 : http://www.public_html/products.php?scatid=72

나는 그것을 같이 할이 : http://www.public_html.com/products/scatid/72

내 PHP 파일이이 같이 내 .htaccess 파일이 포함되어

if($cntrec_prod > 0){ 
    $cnt = 0; 
    mysql_data_seek($srsprod_mst,0);   
    while($srowsprod_mst=mysql_fetch_assoc($srsprod_mst)){ 
     $db_catone_id = $srowsprod_mst['prodcatm_id']; 
     $db_catone_name = $srowsprod_mst['prodcatm_name']; 
     $db_cattwo_id = $srowsprod_mst['prodscatm_id']; 
     $db_cattwo_name = $srowsprod_mst['prodscatm_name'];  
     $db_dys_lft  = $srowsprod_mst['dyslft'];    
     $smlimg_lst  = $srowsprod_mst['prodimgd_simg']; 
     $avl_prd  = $srowsprod_mst['avlprd'];  
     //$lnkname = "products.php?scatid=$db_cattwo_id";   
     $ary_imgnm = explode('--',$smlimg_lst); 
     $img_cnts = ''; 
     $img_frstcnts =''; 
     $imginc = 0; 
     $scatid_lst .= "--".$db_cattwo_id.'-'.$db_dys_lft; 
     for($inc=0;$inc<count($ary_imgnm);$inc++){      
      $scat_imgnm  = $ary_imgnm[$inc]; 
      $scat_imgpth  = $u_sml_upldpth.$scat_imgnm;     
      if(($scat_imgnm != '') && file_exists($scat_imgpth)){ 
       $imginC++; 
       if($inc == 0){ 
        $img_frstcnts = "<a href='products.php?scatid=$db_cattwo_id' class='catImg'><img src='$scat_imgpth' width='300' height='350' border='0' alt=''></a>"; 
       } 
       $img_cnts = "<a href='products.php?scatid=$db_cattwo_id'><img src='$scat_imgpth' width='300' height='350' /></a>";      
      } 
      else{ 
       $img_frstcnts = "<a href='products.php?scatid=$db_cattwo_id' class='catImg'><img src='images/noimage.jpg' width='300' height='350' border='0' alt=''></a>"; 
      } 
     }      
     $dsp_name = $db_cattwo_name;    
?> 

다음 코드 :

RewriteEngine on 
RewriteBase /public_html/ 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php 
RewriteRule products/scatid/(.*)/ products.php?scatid=$1 [L,QSA] 
RewriteRule products/scatid/(.*) products.php?scatid=$1 [L,QSA]` 
+0

'\ $'당신이'$ '기호 대신'/을 탈출하는 잘못된 : 당신은 또한 다음과 같이 마지막 재 작성 규칙을 변경해야합니까? $' –

+0

.htaccess 모든 것이 최선의 방법은 아닙니다. ** 라우터 **를 사용하거나 자신을 프로그래밍하십시오. – Xatenev

+0

변경 사항을 시도해 보니 여전히 URL이 동일해야하는 경향이 있습니다. 제안 주셔서 감사합니다 @ Rahil ny 다른 제안도 hlpful 될 것입니다 – Priyanka

답변

0

다음을 제거해야합니다. 이 COND의 마지막 인스턴스 : URL이 다시 작성되지 않은 경우 콘드 충족 할 수 없기 때문에

RewriteCond %{REQUEST_FILENAME}\.php -f 

이 COND는 재 작성 규칙에 받고에서 당신을 방지 할 수 있습니다./

RewriteRule ^sub-products/([0-9]+)$ sub-products?catid=$1 [NC,L] 
+0

아니요 작동하지 않습니다. @ clami219 – Priyanka

+0

네 말이 맞아! RewriteCond 때문입니다 ... 문제를 해결하기 위해 답을 편집했습니다. – clami219

0

한다 RewriteEngine을 RewriteBase에

#add these 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) /$1/ [R,L] 

RewriteCond %{HTTP_HOST} !^example.nl$ [NC] 
RewriteRule ^(.*)$ http://example.nl/$1 [L,R=301] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 
+0

PHP 파일에서도 href 태그를 변경해야합니까 ?? @Ajay – Priyanka

+0

아니요, 필요 없습니다. –