Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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)
share|improve this question

1 Answer 1

up vote 1 down vote accepted

can you try replace

RewriteRule . /cpu/index.php [L]

by

RewriteRule . /index.php [L]

as for a way to debug...

well you can always var_dump a $wp_query object to get an idea what variables not passed to wp. (you can place ) into first line of your header.php template.

and i belive next step will be debug of rewrites in this case usefull filter is rewrites_array_rules which you can use for debug proposes in a next way

add_filter('rewrite_rules_array', 'rewrite_rules_array_filter_debug', 10000);
    function rewrite_rules_array_filter_debug($rules){
    var_dump($rules);
    return $rules;
}

add this to header php

   <?php 
          global $wp;
          echo '<pre>';
          var_dump($wp);
          echo '</pre>';
   ?>

this shoudl give you a point what rewrite rulle trigger to you page request.

share|improve this answer
    
I get redirected to localhost/xampp after rewriting the .htaccess as you suggested. I reverted back to my initial configuration. I'm trying your function, but I'm not getting any output right now. –  RRikesh Dec 4 '12 at 9:31
    
Oh it the filter upon saving wp-admin/options-permalink.php? I'm updating my question with the results. –  RRikesh Dec 4 '12 at 12:03
    
one more debug code added. –  Oleg Butuzov Dec 4 '12 at 12:30
    
I found the culprit! Big thanks :) –  RRikesh Dec 4 '12 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.