.htaccess Rewriterule没有工作

时间:2017-06-17 11:22:50

标签: wordpress .htaccess url-rewriting wp-rewrite

为什么下面的代码片不起作用?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^custom$ index.php?pagename=mypage [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>


# END WordPress

当我导航到mydomain.com/custom时,它会显示404页面。如果我直接在我的wordpress中写下它,它可以工作,但为什么它在.htaccess里面不起作用?

add_action( 'init', 'add_alexes_rules' );
function add_alexes_rules() {
    add_rewrite_rule('^custom$', 'index.php?pagename=mypage', 'top');
    flush_rewrite_rules();
}

1 个答案:

答案 0 :(得分:-1)

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>