WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#10363 closed defect (bug) (wontfix)

Permalinks with a Static Directory Fail if the Static Directory is Accesed Directly

Reported by: e39m5 Owned by: ryan
Milestone: Priority: normal
Severity: major Version: 2.8
Component: Permalinks Keywords:
Focuses: Cc:

Description

This is fairly straight forward.
My permalink structure is this:
"/blog/%year%/%monthnum%/%postname%/"

If I access myblog.com/blog, a 404 is thrown. I was forced to add a line to the htaccess file that redirects myblog.com/blog to myblog.com. I believe this request should be handled by the software though.

There are two options here, both should be given to the administrator.

The first is to REDIRECT to the root directory, the second is to simply SERVE the root directory.

So, say my permalink structure is this:
"/blog/%year%/%monthnum%/%postname%/"

If "/blog" is accessed and REDIRECT is set, the user will be redirected to the root.
If "/blog" is accessed and SERVE is set, the user will be served the blog at their current location.

I can't think of any reason why someone would choose SERVE because it kills SEO, but you never know.

I can't imagine I'm the only one that wants my page in the root directory while my posts appear in the /blog directory. This is definitely a bug.

Change History (10)

comment:1 @filosofo6 years ago

  • Milestone Unassigned deleted
  • Resolution set to invalid
  • Status changed from new to closed
  • Version 2.8 deleted

Create a page with the slug of "blog." Then select that page as the "posts page" under Settings > Reading, select the page you want as your front page, and click the "a static page" radio button.

Then your most recent posts will appear at /blog/

comment:2 follow-up: @e39m56 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Version set to 2.8

This solves the SERVE solution, but not the REDIRECT, which I'm most interested in.

I want my recent posts to appear on the root, but inside the "blog" directory if someone clicks on it.

So:
www.mydomain.com holds my recent posts.

When you actually detail a post though, it brings you to:
www.mydomain.com/blog/2009/06/post-name or whatever your permalink structure is.

Permalinks allow this, but when you access www.mydomain.com/blog directly, a 404 is thrown. Instead, it should redirect to www.mydomain.com

Unless I'm missing something, this is impossible to accomplish without directly editing Wordpress's .htaccess file. Because permalinks allow for the static directory though, it should know how to handle them.

comment:3 @e39m56 years ago

Just to be clear, my permalink structure is:
"/blog/%year%/%monthnum%/%postname%/"

comment:4 in reply to: ↑ 2 @filosofo6 years ago

Replying to e39m5:

Unless I'm missing something, this is impossible to accomplish without directly editing Wordpress's .htaccess file. Because permalinks allow for the static directory though, it should know how to handle them.

No, you just need something like a custom page template, assigned to the /blog/ page:

<?php
/*
Template Name: Redirect to Home
*/

wp_redirect(get_bloginfo('url'));
exit;

comment:5 @e39m56 years ago

Regardless of the workarounds...shouldn't permalinks handle this?

comment:6 @filosofo6 years ago

Usually WordPress tries to keep the number of admin options to a minimum. Because what you want to do can be done so easily by a theme or plugin and because the need is so obscure, in my opinion it doesn't warrant an admin option.

comment:7 follow-up: @Denis-de-Bernardy6 years ago

  • Resolution set to invalid
  • Status changed from reopened to closed

comment:8 in reply to: ↑ 7 ; follow-up: @e39m56 years ago

  • Resolution invalid deleted
  • Status changed from closed to reopened

So, shouldn't it force a redirect? It seems odd that the software so willingly allows me to create a dead URL. Creating a page to resolve the issue is an obscure solution that requires a ton of unnecessary, extra loading.

comment:9 in reply to: ↑ 8 @filosofo6 years ago

Replying to e39m5:

So, shouldn't it force a redirect? It seems odd that the software so willingly allows me to create a dead URL. Creating a page to resolve the issue is an obscure solution that requires a ton of unnecessary, extra loading.

Why should it force a redirect? There's no reason to assume that a request for /blog/ should redirect to /. Suppose the prefix is several pseudo-directories deep (e.g. /my/permalink/structure/%whatever%/); should WP redirect every request for each of those "directories" (/my/, /my/permalink/, and /my/permalink/) to the root? The current behavior of responding with a 404 makes the most sense for most situations.

There are millions of obscure things that WordPress lets people do; it's powerful and flexible that way. That doesn't imply that core should include an option for all of them.

comment:10 @Denis-de-Bernardy6 years ago

  • Resolution set to wontfix
  • Status changed from reopened to closed

exactly. and then, suppose you've a static front page, and place the blog on a page that resides in /blog. or suppose you use a structure with /blog in it, and you place an archives page over in /blog.

use a plugin that adds the redirect (the suggested page template above will be fine).

Note: See TracTickets for help on using tickets.