I am having a strange issue with permalinks while using the /%postname%/
structure.
I can access my custom post types using the pretty permalink localhost/cpu/<post-type>/<post-title>/
but I am getting a 404 error on Pages. The url of a page is localhost/cpu/<page-title>/
My .htaccess
file (generated automatically when saving permalinks):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cpu/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /cpu/index.php [L]
</IfModule>
# END WordPress
My WordPress(version 3.4.2) installation is in a folder called cpu
. I don't have any issues with the default permalink structure url/?p=123
. The problem does not go away when I disable all plugins.
Any possible solution?
Is there a way to debug what's happening?
UPDATE:
Following Code Monkey's answer, I added the following to functions.php
I changed the filter from rewrite_rules_array
to page_rewrite_rules
- the WP_Rewrite Class reference suggests:
To filter the rewrite rules generated for your Pages, use page_rewrite_rules.
So, here's the code I added:
add_filter('page_rewrite_rules', 'rewrite_rules_array_filter_debug', 10000);
function rewrite_rules_array_filter_debug($rules){
echo '<pre>';
var_dump($rules);
echo '</pre>';
return $rules;
}
And the output from saving the post permalinks on wp-admin/options-permalink.php
:
array(11) {
[".?.+?/attachment/([^/]+)/?$"]=>
string(32) "index.php?attachment=$matches[1]"
[".?.+?/attachment/([^/]+)/trackback/?$"]=>
string(37) "index.php?attachment=$matches[1]&tb=1"
[".?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$"]=>
string(49) "index.php?attachment=$matches[1]&feed=$matches[2]"
[".?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$"]=>
string(49) "index.php?attachment=$matches[1]&feed=$matches[2]"
[".?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$"]=>
string(50) "index.php?attachment=$matches[1]&cpage=$matches[2]"
["(.?.+?)/trackback/?$"]=>
string(35) "index.php?pagename=$matches[1]&tb=1"
["(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$"]=>
string(47) "index.php?pagename=$matches[1]&feed=$matches[2]"
["(.?.+?)/(feed|rdf|rss|rss2|atom)/?$"]=>
string(47) "index.php?pagename=$matches[1]&feed=$matches[2]"
["(.?.+?)/page/?([0-9]{1,})/?$"]=>
string(48) "index.php?pagename=$matches[1]&paged=$matches[2]"
["(.?.+?)/comment-page-([0-9]{1,})/?$"]=>
string(48) "index.php?pagename=$matches[1]&cpage=$matches[2]"
["(.?.+?)(/[0-9]+)?/?$"]=>
string(47) "index.php?pagename=$matches[1]&page=$matches[2]"
}
Anything wrong in it?
UPDATE 2:
I found my error when using var_dump($wp);
.
I got this response:
["query_string"]=>
string(25) "statut-membre=sample-page"
["request"]=>
string(11) "sample-page"
["matched_rule"]=>
string(10) "([^/]+)/?$"
["matched_query"]=>
string(25) "statut-membre=sample-page"
["did_permalink"]=>
bool(true)
Wordpress was querying a taxonomy called statut-membre
while looking for my pages. I noticed I had an empty rewrite slug('rewrite' => array('slug' => ''),
) in that register_taxonomy
function. I added a slug and resaved my permalink structure, now my I can access my pages.
Now the query looks fine too:
["query_string"]=>
string(20) "pagename=sample-page"
["request"]=>
string(11) "sample-page"
["matched_rule"]=>
string(20) "(.?.+?)(/[0-9]+)?/?$"
["matched_query"]=>
string(26) "pagename=sample-page&page="
["did_permalink"]=>
bool(true)