[wp-trac] [WordPress Trac] #22798: Invalid URLs not giving 404 with "Default" permalink settings

WordPress Trac noreply at wordpress.org
Thu Dec 6 23:39:36 UTC 2012


#22798: Invalid URLs not giving 404 with "Default" permalink settings
-----------------------------+---------------------------
 Reporter:  vanchuck         |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Rewrite Rules
  Version:  3.4.2            |   Severity:  normal
 Keywords:                   |
-----------------------------+---------------------------
 '''Steps to reproduce:'''
  - Set up Wordpress with the default .htaccess
  - Select the "Default" option under Permalink Settings
  - Enter an invalid URL eg 'http://blogroot.com/garlbeflax.abc'

 '''Expected Behaviour:'''
  - 404 page is displayed

 '''Observed Behaviour:'''
  - No 404 page is ever shown, no matter what the request string is
  - Instead, Wordpress behaves as if no path was requested, eg displaying
 the homepage/posts lists.
  - If requested url has any of the standard params in it, those params ARE
 executed, eg http://blogroot.com/foo?paged=2 would properly show the 2nd
 page of the posts.

 '''Suspected cause:'''

 In line 620 of wp-includes/class-wp.php (in WP->parse_request), there is a
 conditional which means the only time the request can be marked as a 404
 error is if the array of rewrite rules is NOT empty:
 {{{
         $rewrite = $wp_rewrite->wp_rewrite_rules();

         if ( ! empty($rewrite) ) {
            ...
 }}}

 If the "Default" permalink is selected, and no other rewrite rules are set
 up elsewhere (for reasons I didn't investigate, adding a add_rewrite_rule
 to the theme didn't affect anything), then the $rewrite array IS empty and
 the request can not be checked to see if it's a 404. Therefore, execution
 of the request continues as if no path info were submitted.

 This prevents the showing of the theme's 404 page, and can get a website
 flagged as spam/exploitative in Google's index.

 '''Workaround:'''

 Define a permalink redirect (eg pick one of the options other than
 Default).

 Server info:
 {{{
 Apache/2.2.16 (Debian) (w/ mod_rewrite)
 PHP Version 5.3.3-7+squeeze3 (mod_php5)
 }}}

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

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22798>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list