Rewrite problems

Ce billet en anglais parle de quelques problèmes dans les Rewrite Rules — les règles de réécriture des URLs — dans la nouvelle version WP1.3-alpha-3.

  • 2004-09-10

First bugs. My permalink structure is /category/year/month/postname/. The rewrite rules generated by WP contain the following lines, any of which gave me a 500 Internal Server Error:

RewriteRule ^category/(.+)/(feed|rdf|rss|rss2|atom)/?$ 
/index.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^category/(.+)/page/?([0-9]{1,})/?$ 
/index.php?category_name=$1&paged=$2 [QSA]
RewriteRule ^category/(.+)/?$ /index.php?category_name=$1 [QSA]

[...]

RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/([^/]+)/trackback/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&name=$4&tb=1 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&name=$4&feed=$5 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/([^/]+)/page/?([0-9]{1,})/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&name=$4&paged=$5 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/([^/]+)/?([0-9]+)?/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&name=$4&page=$5 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&feed=$4 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3&paged=$4 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/([0-9]{1,2})/?$ 
/index.php?category_name=$1&year=$2&monthnum=$3 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ 
/index.php?category_name=$1&year=$2&feed=$3 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/page/?([0-9]{1,})/?$ 
/index.php?category_name=$1&year=$2&paged=$3 [QSA]
RewriteRule ^(.+?)/([0-9]{4})/?$ 
/index.php?category_name=$1&year=$2 [QSA]
RewriteRule ^(.+?)/(feed|rdf|rss|rss2|atom)/?$ 
/index.php?category_name=$1&feed=$2 [QSA]
RewriteRule ^(.+?)/page/?([0-9]{1,})/?$ 
/index.php?category_name=$1&paged=$2 [QSA]
RewriteRule ^(.+?)/?$ /index.php?category_name=$1 [QSA]

In all cases but the last one, replacing (.+?) by (.+) corrected the error. For the last rule, I had to resort to ([_0-9a-z-]+). No server errors now. But will the new rules do what they are supposed to? I am obviously no mod_rewrite specialist.

Edit: The solution suggested above turned out to create problems with other rewrite rules: paged monthly archives listings and, very unpleasantly, syndication feeds. The solution is — at least it works for the moment — to replace the (.+) with ([_0-9a-z-]+) in all cases.


2 comment(s) for 'Rewrite problems'

  1. (Comment, 2004-09-06 21:56 )
    #1 — Neil

    Changing the (.+?) to (.+) worked for me using the same permalink structure generated by the 1.3-alpha-3 release. However I didn’t have to change the last rule you mentioned. Thanks for you insight into fix!

  2. (Trackback, 2004-09-10 09:26 )
    #2Odyssey

    Category issue solved (for now)
    A few days ago, when I upgraded to Wordpress 1.3-alpha-3 and Kubrick V1.2.5, I faced an issue with permalinks . I wanted to use Clean URLs. But it wasn’t working at all. I followed the steps given by Wordpress : Option—> Permalinks—>…