• 1. This doesn’t work in Apache <2.0. I’ve convinced myself of that by playing around with it the RewriteRules a whole heck of a lot.

    First question:
    Anyone know of good hosts that run Apache 2.0? All the ones that I’ve seen seem to run Apache 1.3.33. I’m pestering my host to upgrade, but we’ll see how that goes.

    2. I’ve worked out a kinda/sorta workaround hack that allows you to have category links like /category/%category% and permalinks like /%category%/%postname%. Basically, I just took the regexes created by WP for mod_rewrite, and ported them into a php script that parses the request URI using preg_replace. If nothing matches, then it sets the $_SERVER['PATH_INFO'] var, and hopes for the best. It seems to be working.

    However, I’d really like to release this as a plugin, but I’m a total WP noob. In order to make it a plugin, I’m sure that you’d want to be able to have the script do things in a more generalized way, perhaps using some of the same logic that generates the .htaccess rules. Then, the permalink management page could perhaps:

    1. Sniff for Apache version. If >= 2, do what you’re doing now.
    2. If < 2, then write a simpler .htaccess file, like so:
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /wp/
      RewriteCond %{REQUEST_FILENAME} -f [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^.*$ - [S=39]
      RewriteRule ^(.*)$ /wp/uricruncher.php
      </IfModule>

      Then, write the “actual” rules to uricruncher.php. (Or, perhaps that file could contain a function that does what I’m doing in a more generalized way, based on the permalink settings.)

    If any WP gurus want to give me a few pointers to get started making that happen, I think we may end up with a plugin to reliably make %category% permalinks work in Apache 1.3.

    Second Question:
    Does anyone know the relative server strain with using mod_rewrite vs. preg_replace? I wonder if this method will drag things down or strain the server too much by calling preg_replace about 40 times in a row.

    Third Question:
    Let’s say that you have a post in child-category, which is a child of parent-category. You also have a “page” that is a child of a parent page.

    I’m wondering how it can tell the difference between
    /parent-category/child-category/post-name
    and
    /this-is-a-page/this-is-a-child-page

    I can’t seem to figure out how to handle this in the preg_replace rules that are chomping the URI. If I rewrite the second one to index.php/this-is-a-page/this-is-a-child-page, it works fine, but if I rewrite the first one to index.php/parent-category/child-category/post-name, then I get the 404 page. But how can the script tell the difference between the two, since they match exactly the same regex?
    Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter isaacschlueter

    (@isaacschlueter)

    I think I might have solved my own problem. This .htaccess handles everything, without the need for a separate script. (Note: if you haven’t installed to the /wp/ directory, then you’ll want to replace all instances of /wp/ with your wordpress directory.)

    Sorry for taking up space in the forum, but hopefully this thread will be a helpful search result for someone:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /wp/
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [S=39]
    #RewriteRule ^(.*)$ /wp/uricruncher.php
    RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /wp/index.php?year=$1&paged=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/?$ /wp/index.php?year=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /wp/index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /wp/index.php?year=$1&monthnum=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /wp/index.php?year=$1&monthnum=$2&day=$3&feed=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /wp/index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /wp/index.php?year=$1&monthnum=$2&day=$3 [QSA,L]
    RewriteRule ^(.*)$ /wp/index.php?error=404/$1 [QSA,L]
    </IfModule>

    Thread Starter isaacschlueter

    (@isaacschlueter)

    That didn’t end up working.

    However, this plugin does.

    🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Êtegory% in Permalink – Actually Possible?’ is closed to new replies.