2017-04-25 98 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