2017-06-17 53 views
1

为什么以下代码段不起作用?.htaccess重写代码不工作

# 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(); 
} 
+0

也许'mod_headers'模块不包括 – Deadooshka

+0

@Deadooshka我mod_headers中删除,并没有影响。 – HOY

+0

如果您直接请求'/index.php?pagename=mypage',是否“有效”? – MrWhite

回答

-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> 
+1

这个问题问为什么他们的.htaccess代码无法正常工作。即使你提供了工作代码,如果你描述你的代码为什么更好/问题是什么,它会更好。 –