2017-06-17 97 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代碼無法正常工作。即使你提供了工作代碼,如果你描述你的代碼爲什麼更好/問題是什麼,它會更好。 –