samir
samir

Reputation: 137

Wordpress URL not working

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?

Upvotes: 0

Views: 246

Answers (2)

Samir Sheikh
Samir Sheikh

Reputation: 2401

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);

Upvotes: 1

Ahmed Ginani
Ahmed Ginani

Reputation: 6650

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);

Upvotes: 0

Related Questions