WordPress.org

Forums

[resolved] redirect /oldStaticDir/index.html to /newWPDirectory (5 posts)

  1. jbusci
    Member
    Posted 3 years ago #

    So I am almost finished moving a static site on to wordpress.

    The old site structure was in the following format -

    http://domain.com/index.html

    http://domain.com/sub1/index.html
    http://domain.com/sub1/page1.html
    http://domain.com/sub1/page2.html
    http://domain.com/sub1/page3.html

    http://domain.com/sub2/index.html
    http://domain.com/sub2/page1.html
    http://domain.com/sub2/page2.html

    http://domain.com/sub3/index.html
    http://domain.com/sub3/page1.html

    What I have managed to accomplish thus far.
    I have all the images loaded in the database and doing the right thing in both wp-admin visual editor and on the pages.
    Same for my JS and CSS files.
    Created a theme for this site from scratch.

    The way I handled my sub-directory index pages was to create a wp-category for each sub-directory. So what I have in wordpress is
    categories for sub1, sub2, and sub3
    I used custom permalink structure /%category%/%postname%.html
    and created posts for each page and assigned the category.
    For example I have page1 in category sub1. So the url becomes just as you would expect.

    The solution I am working on involves creating category templates to handle the index.html for that category and redirecting canonical links to the category url.

    For example, I have category-sub1.php.

    in this file, I am running a loop that only shows content of a post that I have named sub1-index, and I am redirecting that page sub1-index.html to sub1 in .htaccess.

    Here is the problem. When I request
    http://domain.com/sub1/index.html I am redirected to
    http://domain.com/sub1
    and I get the content of the post sub1-index
    THIS IS GREAT!

    BUT When I request
    http:/domain.com/sub2/index.html I am redirected to
    http://domain.com/sub1

    WHY!?!?!?!?!?!?!?!

  2. jbusci
    Member
    Posted 3 years ago #

    i know this is a tough problem, right?

    One thing I probably should have mentioned.

    I tried to create multiple index.html files under the categories. But quickly realized that wordpress won't allow me to have pretty permalinks using the same post name even if they are in the same category.

    This might be an advanced topic.

  3. jbusci
    Member
    Posted 3 years ago #

    So wordpress was indeed functioning as it should. apparently my RewriteCond was too verbose and wordpress rescued me by gracefully serving up the closest match it could find for the index.html I was calling.

    Here is the working rewrite rule. of course substitute http://www.domain.com

    RewriteCond %{THE_REQUEST} ^([^/]+/)*index\.html\ HTTP/
    RewriteCond %{THE_REQUEST} ^.*/index\.html
    RewriteRule ^(([^/]+/)*)index.html$ http://www.domain.com/$1 [R=301,L]
  4. jbusci
    Member
    Posted 3 years ago #

    resolved

  5. jbusci
    Member
    Posted 3 years ago #

    lol ooops

Topic Closed

This topic has been closed to new replies.

About this Topic