WordPress.org

Ready to get started?Download WordPress

Forums

WordPress pages for subdirectory of same name (2 posts)

  1. J. Hai
    Member
    Posted 5 years ago #

    I have "pretty" permalinks on for my site and have a page with the same name as a subdirectory, e.g. http://www.domain.com/sub/

    When you go to that URL, though, the browser displays the contents of the subdirectory instead of the page. Is there any way to override this and display the WordPress page instead?

  2. J. Hai
    Member
    Posted 5 years ago #

    Okay, I've found a workaround for this problem and am posting it here in case it helps someone else.

    What situation is this useful for?
    In my case, I'm running a setup with one main site and multiple sub-blogs under separate WordPress installs. The main site is located on the top level domain, while the sub-blogs are located under /blogs/blog1, /blogs/blog2, etc.

    Now when visitors want to see a list of all the blogs, they'll intuitively want to go up one level to /blogs/. I wanted this to pull up a page from the WordPress install on the main site that lists all the blogs and their RSS feeds.

    This wasn't possible, however, because WordPress by default checks to see if a subdirectory exists and goes to that instead of a page of the same name. The workaround I describe below isn't seamless, but it gets the job done well enough from a user browsability standpoint.

    Here are the steps:
    1) Create a blank index.html file and place it in the top level of your subdirectory.

    2) Edit the WordPress page that has the same name as the subdirectory. Change its permalink slightly (for example, in my case I changed it from /blogs to /blogs-all) to distinguish it from the subdirectory.

    3) Open up the .htaccess file (or create a new one if you don't have one yet) in the root of your WordPress install and add the following line, replacing yourdomain and blogs with your own domain and subdirectory names.

    redirect 301 /blogs/index.html http://www.yourdomain.com/blogs-all

    Now anytime a visitor goes to http://www.yourdomain.com/blogs/, they'll be automatically redirected to the WordPress page of your choosing.

Topic Closed

This topic has been closed to new replies.

About this Topic