2017-04-25 14 views
0

wordpress를 사용하고 있습니다. 일부 URL 문제가 있습니다.Wordpress URL이 작동하지 않습니다.

나의 현재 URL은 서버의 IP 주소입니다 : http://www.192.10.1.22/states/?q=ohio

내가 원하는 URL : http://www.192.10.1.22/states/ohio

내가 functions.php 파일에 다음 코드를 사용하고 내 지역에서 일하고있어하지만 난에 업로드 할 때 cpanel 그때 그것은 오류가 페이지를 찾을 수 없습니다 작동하지 않습니다.

function custom_rewrite_rule() { 
     add_rewrite_rule(  
      'states/([^/]*)/?',   
      'index.php/states/?q=$1',   
      'top'); 
    } 

    add_action('init', 'custom_rewrite_rule', 10, 0); 

또한 코드 밑도는.

add_rewrite_tag('%states%', '([^&]+)'); 
global $wp; 
    $wp->add_query_var('q'); 
    add_rewrite_rule(
     'states/(\d*)$', 
     'index.php/states?q=$matches[1]', 
     'top' 
    ); 

또한 permalink 및 apache mode_rewrite도 업데이트됩니다.

어떻게이 문제를 해결할 수 있습니까?

답변

1

코드에 따라 사용하십시오.

먼저 선언 쿼리 VAR는

function custom_rewrite_rule() { 
global $wp; 
$wp->add_query_var('q'); 
    add_rewrite_rule(
     'states/(/([^/]+))?(/([^/]+))?/?', 
     'index.php?pagename=states&q=$1', 
     'top' 
    ); 
} 

add_action('init', 'custom_rewrite_rule', 10, 0); 
+0

감사합니다! 그것은 작동 중입니다 ... 고마워요 :) – samir

+0

그것은 내 기쁨입니다. –

0

서버의 .htaccess 파일에 규칙을 직접 추가 할 수 있습니다.

function custom_rewrite_rule() { 
    add_rewrite_rule('^states/([^/]*)/([^/]*)/?','index.php?q=$matches[1]','top'); 
    } 
    add_action('init', 'custom_rewrite_rule', 10, 0); 
+0

내가 페이지를 찾을 수 없습니다 내게 주신 직접 htaccess로 파일하지만 회전식 문에 그 코드를 사용했다. – samir

+0

index.php를 추가하십시오 : RewriteRule^states/([^ /] *) /? /index.php/states/?q=$1 [QSA, L] –

+0

여전히 찾을 수 없습니다. – samir

관련 문제