skip to Main Content

I am using wordpress, i have some URL issue.

My current URL is IP address on server: http://www.192.10.1.22/states/?q=ohio

I want URL :http://www.192.10.1.22/states/ohio

i used following code in functions.php file and it’s working in my
local but when i upload in cpanel then it’s now working given me error
page not found.

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

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

i also used below code.

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

i also update permalink and apache mode_rewrite is also on.

so how could i solve this issue?

2

Answers


  1. You can directly add the rule in your .htaccess file on server.

        function custom_rewrite_rule() {
        add_rewrite_rule('^states/([^/]*)/([^/]*)/?','index.php?q=$matches[1]','top');
        }
        add_action('init', 'custom_rewrite_rule', 10, 0);
    
    Login or Signup to reply.
  2. Please Used Following code.

    First declare query 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);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search