2017-04-25 100 views
0

我使用wordpress,我有一些網址問題。WordPress的網址不工作

我目前的URL是服務器的IP地址:http://www.192.10.1.22/states/?q=ohio

我想網址: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' 
    ); 

我也更新固定鏈接和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