admin管理员组文章数量:1122846
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 an 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 update permalink and apache mode_rewrite is also on. So how could I solve this issue?
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 an 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 update permalink and apache mode_rewrite is also on. So how could I solve this issue?
Share Improve this question edited Apr 26, 2017 at 11:23 Faysal Mahamud 1,0402 gold badges8 silver badges21 bronze badges asked Apr 26, 2017 at 5:05 user118443user118443 12 Answers
Reset to default 0This is not how rewrite_rules
works in Wordpress.
You miss two things.
- Match. It has
$1
, but in reality (take a look to example), you need to work with$matches
. - 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. - 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_rewrite_rule('^states/([^/]*)/?','index.php?post_type=page&pagename=states&state_names=$matches[1]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);
flush_rewrite_rules();
本文标签: htaccessWordpress URL not working
版权声明:本文标题:htaccess - Wordpress URL not working? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295764a1929641.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论