• firstly – this is probably the one feature I was waiting for the most.. so yay.
    However… here’s my question:
    in regular posts I have the format
    /%category%/%year%/%monthnum%/%postname%/
    which is great.. but I’d like the Category links at the side (and in general) to just be /%category%/ not /whatever/%category%/ which they are atm.
    its a) counter-intuative for users, and b) screws up how I’d like to navigate my site.
    I cant’ put a blank value in the box, because that defaults to “category” which sucks… any suggestions without getting down and dirty with mod_rewrite myself? It does seem like it should be possible, the current default behvaior seems broken to me..

Viewing 15 replies - 1 through 15 (of 25 total)
  • Thread Starter darkcryst

    (@darkcryst)

    No-one? I know the question has been asked before.. but no-one answered it, and ended up talking about completely unrelated permalink issues.
    This can’t be that hard.. surely?

    Moderator James Huff

    (@macmanx)

    As far as I know, /%category%/ is not a permalink tag support by WordPress. if you’ve figured out how to use it, congrats. However, there is no way to get ride of the /archives/ in /archives/%year%/ etc. So, I would assume that if you got /%category%/ to work, then there is no way to get rid of the /category/ before it. Saadiq had the right idea with, “Otherwise, WP wouldn’t be able to tell the difference between a subdirectory on the filesystem and a category rewrite.”

    Yes, you get fall through if you start your permalink structure with %category%. We need to take advantage of this with regard to the category structure. Typically, the category structure requires a fixed string prefix such as /category/ to prevent the very greedy rewrite rule for %category% from gobbling up everything and interfering with the permalink structure. But, if the permalink structure begins with %category%, you get nice fall through and no collision. If you want, write a bug mentioning that the category structure should be more flexible in this regard.
    BTW, in 1.3, the rewrite rules are not processed if the requested URI matches a real file or directory. The rules won’t eclipse things that actually exist in the filesystem. Look at the RewriteConds in 1.3’s rules.

    Thread Starter darkcryst

    (@darkcryst)

    I hate to argue with such fine people… but %category% actually doesn’t work as a fall through.
    Example: I have set up the structure of:
    /%category%/%year%/%monthnum%/%postname%/
    say I have a category “news” https://www.myurl.com/news/ does NOT go to that category. I can only get to it via https://www.myurl.com/category/news
    or what ever I have set the category part to be.
    Mind you my nightly build is a few days old, could this make the difference? Otherwise.. it doesn’t work how you describe. Which is annoying. wierdly though the post link is correct, but it doesn’t work the other way. Odd huh?

    Thread Starter darkcryst

    (@darkcryst)

    You know… scratch all this. I’m an idiot.. thank for listening.
    However.. I’m glad I got some GREAT responces!
    The ritual whipping may now begin…

    wait, DarkCyst, does it work now or not? What did you do to get it to work? I *hate* having to use category – because mine arn’t all categories! ??

    To remove the word “category” in category permalinks, you need to change the following line in wp-includes/classes.php:


    $this->category_structure = $this->front . 'category/';

    into this:


    $this->category_structure = $this->front;

    This is in get_category_permastruct() method. WP’s mod-rewrite rules already cover URL’s like this, so no problems there. I’m building the theme for my blog and this works great so far. I’ll report if I encounter problems with it.

    Of course, this is all in WP 1.5

    Well… i don’t know what i’m doing wrong, i try to hack the wp-includes/classes.php as aleck said but when i click in the category
    it gives my a 404 page not found…

    can somenone help me on this???

    i’m using 1.5 Strayhorn if this helps.

    Thank’s

    DONE !

    well my fault i forgot to update my permalink structure after change the classes.php file. eheheh

    I did this and my links to the individual entries did not work.

    Just because I need a definitive answer- MUST all permalinks in v1.5 refer to either the post ID or the date? I’m switching from MT, so the lack of this kind of category support is stumping me. (FYI: at this point, I messed up my site so bad, i dropped the tables and re-installed, so the links mentioned below are gonzo).

    I was able to configure the categories as outlined above, using the change to the classes file.

    In the Permalinks area, I had only:
    /%category%/%postname%/

    I got some great permalinks then, but the link to the individual entry was broken. So I was able to see listing pages at:
    https://site.kidsown.ie/category/
    and also:
    https://site.kidsown.ie/category/subcategory/

    But I was not able to see any

    https://site.kidsown.ie/category/postname

    Nor did any date archives work.

    I’d be grateful if someone set me straight… Is it just plain impossible in WP v1.5 to duplicate the directory structure I had in MT?

    nearlythere, there is a bug in the way WP 1.5 is writing down mod_rewrite rules in .htaccess

    Look in there, and you will see that it writes category rules (about 4-5 of them) before monthly-archive and single-post rules. Just moved them to the end of the WP section, and all will work.

    This happend to me too, but only after I added few Pages (new feature in WP1.5).

    aleck! you’re a star. i’m going to try this right now. LOL, i had just given up on the entire subject, and so i have to start from scratch now. i’ll take notes as i go, this should be added as a ‘how-to guide.’

    1- edit wp-includes/classes.php

    $this->category_structure = $this->front . 'category/';

    into this:
    $this->category_structure = $this->front;

    2- edit permalink structure in wordpress admin area; options > permalinks.

    structure: /%category%/%postname%/

    3- click ‘update permalink structure’. page reloads. do not allow WP to edit your .htaccess. instead, update your .htaccess manually. copy and paste rewrite rules. into text document from bottom of permalinks page in WP admin area.

    4- look for category rules, and move them to the end of the WP section.

    ok! this is where i’m stumped, i don’t see any ‘category rules’… can you give me an example of what the group of category rules might look like? (is this because i did the modification to the classes file- should i not do this?)

    if you can bear it, here is what WP spit out for my .htaccess (i had to go in, and overwrite the old one, since it was getting seriously messed up with mad duplication.) which lines should be moved?

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ – [S=45]
    RewriteRule ^(about-us/team-members)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(about-us/team-members)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(about-us/team-members)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L]
    RewriteRule ^(about-us/team-members)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L]
    RewriteRule ^(about-us/team-members)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L]
    RewriteRule ^(about-us)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(about-us)/(feed|rdf|rss|rss2|atom)/?$ /index.php?pagename=$1&feed=$2 [QSA,L]
    RewriteRule ^(about-us)/page/?([0-9]{1,})/?$ /index.php?pagename=$1&paged=$2 [QSA,L]
    RewriteRule ^(about-us)/?([0-9]+)?/?$ /index.php?pagename=$1&page=$2 [QSA,L]
    RewriteRule ^(about-us)/trackback/?$ /index.php?pagename=$1&tb=1 [QSA,L]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /index.php?s=$1&paged=$2 [QSA,L]
    RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L]
    RewriteRule ^(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&feed=$2 [QSA,L]
    RewriteRule ^(.+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&paged=$2 [QSA,L]
    RewriteRule ^(.+)/?$ /index.php?category_name=$1 [QSA,L]
    RewriteRule ^author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /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)/?$ /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)/?$ /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,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?category_name=$1&name=$2&feed=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/page/?([0-9]{1,})/?$ /index.php?category_name=$1&name=$2&paged=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/?([0-9]+)?/?$ /index.php?category_name=$1&name=$2&page=$3 [QSA,L]
    RewriteRule ^(.+)/([^/]+)/trackback/?$ /index.php?category_name=$1&name=$2&tb=1 [QSA,L]
    </IfModule>

    ok, let me pick up where i left off!! I had moved some lines, and tested the site, but it appeared not to work. i fact it was working, but only if you don’t have sub-categories. (the sub-category pages return a WP 404 file not found error).

    so if we pick up at number 4 above, i moved these lines:


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

    to the bottom, above, the final closing of </IfModule>

    So it works… but only if you don’t have sub-categories.

    at this point, this means i can see these links to single entries:
    https://site.kidsown.ie/portfolio/projects/unheard-voices/

    and i can see this archive page:
    https://site.kidsown.ie/portfolio/

    but i can’t see the sub-category archive page:
    https://site.kidsown.ie/portfolio/projects/

    any advice on this past hurdle, and i think we’ll have ourselves a tidy little fix here. i’d be glad to post it on the wiki, and write it up.

    I’ve just started with WP but, after following this thread, I’ve gotten the category and sub-category pages to work just fine. However, I am just starting so I’ll probably screw it up in a day or two.

    So, if it helps, here’s the rewrite rules I ended up with…

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ – [S=43]
    RewriteRule ^feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1 [QSA,L]
    RewriteRule ^page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^comments/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/(feed|rdf|rss|rss2|atom)/?$ /index.php?&feed=$1&withcomments=1 [QSA,L]
    RewriteRule ^comments/page/?([0-9]{1,})/?$ /index.php?&paged=$1 [QSA,L]
    RewriteRule ^search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?s=$1&feed=$2 [QSA,L]
    RewriteRule ^search/(.+)/page/?([0-9]{1,})/?$ /index.php?s=$1&paged=$2 [QSA,L]
    RewriteRule ^search/(.+)/?$ /index.php?s=$1 [QSA,L]

    RewriteRule ^author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ /index.php?author_name=$1&feed=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/page/?([0-9]{1,})/?$ /index.php?author_name=$1&paged=$2 [QSA,L]
    RewriteRule ^author/([^/]+)/?$ /index.php?author_name=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&feed=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/page/?([0-9]{1,})/?$ /index.php?year=$1&paged=$2 [QSA,L]
    RewriteRule ^([0-9]{4})/?$ /index.php?year=$1 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ /index.php?year=$1&monthnum=$2&feed=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ /index.php?year=$1&monthnum=$2&paged=$3 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/?$ /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)/?$ /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)/?$ /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,})/?$ /index.php?year=$1&monthnum=$2&day=$3&paged=$4 [QSA,L]
    RewriteRule ^([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ /index.php?year=$1&monthnum=$2&day=$3 [QSA,L]

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

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

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

    I also found that if I let WP write to my .htaccess everything went to crap. However, if I copied the rewrite rules from the “Edit Permalink Structure” screen, it worked like a charm. Of course, I still had to move the category rules to the bottom as aleck suggested. Hope that helps!

    That does, thanks.

    Now I’ve found that if you use the ‘page feature’ you have to manually edit the .htaccess each time.. remembering to move the category lines down to bottom.

    I think I’m about to abandon this hack altogether… ??

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘Category Permalinks’ is closed to new replies.