admin管理员组

文章数量:1025299

I'm not sure if this is 'normal' but on my WP install the actual directory for 'category' throws a 404 error.

So, for example, if I had a category called 'apples' then every post or page associated with the 'apples' category has this URL string:

my-site/category/apples/ 

The above for me loads fine.

However, if I remove the 'apples' from the URL then a 404 error is generated, which I am sure is correct, or should there be an index page or other?

The reason I am asking about this is because I created some custom Taxonomy called 'US States' which works like this:

my-site/us-states/florida < loads great with archive

my-site/us-states/ < Error 404

Is there anyway to make the HOME of the actual taxonomy a templated page or other?

Thanks

I'm not sure if this is 'normal' but on my WP install the actual directory for 'category' throws a 404 error.

So, for example, if I had a category called 'apples' then every post or page associated with the 'apples' category has this URL string:

my-site/category/apples/ 

The above for me loads fine.

However, if I remove the 'apples' from the URL then a 404 error is generated, which I am sure is correct, or should there be an index page or other?

The reason I am asking about this is because I created some custom Taxonomy called 'US States' which works like this:

my-site/us-states/florida < loads great with archive

my-site/us-states/ < Error 404

Is there anyway to make the HOME of the actual taxonomy a templated page or other?

Thanks

Share Improve this question edited Apr 8, 2019 at 5:22 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Apr 8, 2019 at 4:47 HenryHenry 9831 gold badge8 silver badges31 bronze badges 1
  • 2 This is the standard behaviour, yes. By default all URLs in WordPress are lists of posts or single posts. There are no posts that it would make sense to display at such a URL. – Jacob Peattie Commented Apr 8, 2019 at 5:02
Add a comment  | 

2 Answers 2

Reset to default 2

Yes, it's normal behavior. WordPress uses a set of rewrite rules to process requests. Here are the rules that will match requests related to categories:

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

As you can see, all of them require, that the request is longer than /category/.

And it makes sense.

  • category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/ - will match the feed for category
  • [category/(.+?)/(feed|rdf|rss|rss2|atom)/ - is a shorter URL for feed
  • category/(.+?)/page/?([0-9]{1,})/ - is support for pagination
  • category/(.+?)/ - is just category listing (first page)

So all of the URLs above are related to given term in this taxonomy and you know which term, because it is defined in URL.

On the other hand, what should be displayed when you go to /category/? No term is defined, so you can't select any one of them. So should it show you all posts on your site? (Blog index already does it).

Sometimes it makes sense to show the list of categories on such URL, but it isn't a common practice.

You can always add your custom rewrite rule to process such requests.

You can create template files for each level of the category tree. Also for the one you mentioned. If you create a template called category.php or archive.php WordPress will load it on this level. Place it in your themes root folder.

Find more detailed info on the view hierarchy here: https://developer.wordpress/themes/basics/template-hierarchy/#examples

I'm not sure if this is 'normal' but on my WP install the actual directory for 'category' throws a 404 error.

So, for example, if I had a category called 'apples' then every post or page associated with the 'apples' category has this URL string:

my-site/category/apples/ 

The above for me loads fine.

However, if I remove the 'apples' from the URL then a 404 error is generated, which I am sure is correct, or should there be an index page or other?

The reason I am asking about this is because I created some custom Taxonomy called 'US States' which works like this:

my-site/us-states/florida < loads great with archive

my-site/us-states/ < Error 404

Is there anyway to make the HOME of the actual taxonomy a templated page or other?

Thanks

I'm not sure if this is 'normal' but on my WP install the actual directory for 'category' throws a 404 error.

So, for example, if I had a category called 'apples' then every post or page associated with the 'apples' category has this URL string:

my-site/category/apples/ 

The above for me loads fine.

However, if I remove the 'apples' from the URL then a 404 error is generated, which I am sure is correct, or should there be an index page or other?

The reason I am asking about this is because I created some custom Taxonomy called 'US States' which works like this:

my-site/us-states/florida < loads great with archive

my-site/us-states/ < Error 404

Is there anyway to make the HOME of the actual taxonomy a templated page or other?

Thanks

Share Improve this question edited Apr 8, 2019 at 5:22 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Apr 8, 2019 at 4:47 HenryHenry 9831 gold badge8 silver badges31 bronze badges 1
  • 2 This is the standard behaviour, yes. By default all URLs in WordPress are lists of posts or single posts. There are no posts that it would make sense to display at such a URL. – Jacob Peattie Commented Apr 8, 2019 at 5:02
Add a comment  | 

2 Answers 2

Reset to default 2

Yes, it's normal behavior. WordPress uses a set of rewrite rules to process requests. Here are the rules that will match requests related to categories:

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

As you can see, all of them require, that the request is longer than /category/.

And it makes sense.

  • category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/ - will match the feed for category
  • [category/(.+?)/(feed|rdf|rss|rss2|atom)/ - is a shorter URL for feed
  • category/(.+?)/page/?([0-9]{1,})/ - is support for pagination
  • category/(.+?)/ - is just category listing (first page)

So all of the URLs above are related to given term in this taxonomy and you know which term, because it is defined in URL.

On the other hand, what should be displayed when you go to /category/? No term is defined, so you can't select any one of them. So should it show you all posts on your site? (Blog index already does it).

Sometimes it makes sense to show the list of categories on such URL, but it isn't a common practice.

You can always add your custom rewrite rule to process such requests.

You can create template files for each level of the category tree. Also for the one you mentioned. If you create a template called category.php or archive.php WordPress will load it on this level. Place it in your themes root folder.

Find more detailed info on the view hierarchy here: https://developer.wordpress/themes/basics/template-hierarchy/#examples

本文标签: categoriesShould the actual category directory be 404 Is that normal WP behaviour