0

I am using wordpress, i have some URL issue.

My current URL is : http://www.example.com/states/?q=ohio

I want URL :www.example.com/states/ohio

i want to remove ? mark form url.

without adding code in htaccess when i call URL http://www.example.com/states/ohio. it given me page not found error.

so how could i solve this issue?

ɢʀᴜɴᴛ
  • 32,025
  • 15
  • 116
  • 110
samir
  • 137
  • 2
  • 10

2 Answers2

0

Could use something like this as your htacces file:

RewriteEngine On
RewriteBase /
RewriteRule ^states/([a-zA-Z0-9-_]+)/?$ /states/?q=$1 [NC,L,QSA]

Visiting http://www.example.com/states/ohio/ should now resolve to /states/?q=ohio

If not check your apache logs and that the page can be directly accessed

atoms
  • 2,993
  • 2
  • 22
  • 43
0

I have done the same thing previously using add_rewrite_rule.

Try to use this code,

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

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

Do not forget to update your permalink after adding this into "function.php" file.

It should work for you. Thanks.

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33