I am using Wordpress, I have some URL issue.

My current URL is IP address on server: http://www.

I want URL: http://www.

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 an error page not found.

function custom_rewrite_rule() {
            'top' );

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

I also update permalink and apache mode_rewrite is also on. So how could I solve this issue?

2 Answers 2


This is not how rewrite_rules works in Wordpress. You miss two things.

  1. Match. It has $1, but in reality (take a look to example), you need to work with $matches.
  2. Your Query Var. You using q, but its not wp native or declared in example code. You can use one of the public ones or declare your query var and logic behind it.
  3. If you are OK with Regular Expressions and already implemnt first two changes, but it still doesn't work - I would suggest to use debug bar and my plugin debug bar rewrite rules

Add the following code in the functions.php

add_filter('query_vars', 'add_state_var', 0, 1);
function add_state_var($vars){
    $vars[] = 'state_names';
    return $vars;

function custom_rewrite_rule() {

add_action('init', 'custom_rewrite_rule', 10, 0);
  • This will bring to running flush_rewrite_rules()every single request. Commented Apr 27, 2017 at 7:55
  • Once run flush_rewrite_rules just comment that line. Commented Apr 27, 2017 at 12:06
  • Should you add this to code or something? Commented Apr 27, 2017 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.