Support » Fixing WordPress » custom .htaccess rewrite rules

  • Resolved APTM

    (@antonputtemans)


    I have my WordPress installed at:
    mysite/blog/
    I want the about page to be accessible with:
    mysite/about/

    I tried setting up an .htaccess file in the root with:
    RewriteRule ^about(.*)$ blog/?page_id=203$1 [L,NC]

    This works, but pulls to:
    mysite/blog/about/
    because interfears with WordPress’ .htaccess (I use the pretty permalinks)

    I tried adding the rewrite rule above the # BEGIN WordPress – # END WordPress block but no luck.
    I am also not sure about the RewriteBase as I want to target up level up.

    Thanks for any help

Viewing 14 replies - 1 through 14 (of 14 total)
  • APTM

    (@antonputtemans)

    Anyone please?

    You may find that WordPress’ .htaccess in your blog directory interfering with your original redirect. You may need to put something specific into your /blog/.htaccess to handle the about page, as well as the one in root.

    Remember that the rewritebase for the initial redirect is / but by the time it gets to the /blog/ directory it’s already been rewritten.

    APTM

    (@antonputtemans)

    I tried RewriteRules in my root and /blog/ folders.
    I tried every possible path and combinations but mysite/blog/ keeps getting forwarded to mysite/blog/about

    I also tried the custom permalinks plugin and even changing the post_name in the database.. nada.
    Why is this so difficult?
    I have successfully made a page outside the wp directory with importing wp-blog-header.php but when someone comments on this page, gets forwarded to mysite/blog/about/#comment-1
    Is there any way to go that route?

    So have you got two different about pages? I’m confused why having it redirect to /blog/about is wrong.

    APTM

    (@antonputtemans)

    Mr Mist, no I have only one about page and I just want to have the URL to be mysite/about/, without the /blog/ part.
    Thank you

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Plugin Review Team Rep

    antonputtemans, if you do this Giving WordPress Its Own Directory, that will work by default.

    APTM

    (@antonputtemans)

    Thanks for the help ipstenu, unfortunately this is not a solution for me as I have photoblog software (Pixelpost) installed in my root so my /index is already occupied.

    Is there really nothing I can rewrite on top of WP’s?
    I don’t need any regular expressions or anything, just the About page.

    APTM

    (@antonputtemans)

    edit: sorry, double posted

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Plugin Review Team Rep

    antonputtemans, since you have pixelpost there, you’ll likely run into conflicts. Your best bet would be to move Pixelpost to a subfolder and then decide which one you want to run off ‘root’. But you can’t have both.

    Since you want your about page to appear separate from your blog (a different base URL), why not just make it a static html page and then link to it from your blog? That’s what I did for my privacy policy.

    APTM

    (@antonputtemans)

    yeah thanks ipstenu, I can’t change my Pixelpost structure anymore, that’s why I need to do the WP voodoo.

    Iridiax, yes I tried mading a page outside the wp directory with importing wp-blog-header.php
    It works great, but when someone comments on this page, (which is the whole reason I want a WP page there) gets forwarded to mysite/blog/about/#comment-1

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    πŸ³οΈβ€πŸŒˆ Plugin Review Team Rep

    That’s kinda how it’s gonna have to work. Unless you did a frame or something to include the page.

    @antonputtemans:

    If all you’re trying to do is rewrite a single URL on one PHP-interpreted page, then you can use PHP’s built-in output buffering to find-and-replace the “incorrect” URL that WordPress generates with the “correct” URL that you want to use. To do this, simply place this line of PHP code right before the first output:

    ob_start();

    Then at the very bottom of your template, after the </html>, put the following PHP code:


    $page_content = ob_get_contents();
    $replace_this = 'href="http://mysite.com/blog/about/';
    $with_this = 'href="http://mysite.com/about/';
    $modified_page_content = str_replace($replace_this, $with_this, $page_content);
    ob_end_clean();
    echo $modified_page_content;

    I’m not certain if this is going to be a solution for your particular situation, but with the above code in place, I can guarantee that the URL you’re saying is pointing to the “wrong” place will now point to the “correct” place (i.e., without the /blog/ part of the URL).

    Good luck.

    APTM

    (@antonputtemans)

    Thanks Meitar, but I just wanted to rewrite the URI.

    Anyway in a response to Iridiax, as I am going the way of an external page importing importing wp-blog-header.php
    I just found you can send the redirect dir to fix my problem in
    http://wordpress.org/support/topic/229621#post-941167

    All it takes is adding to the form:
    <input type=”hidden” name=”redirect_to” value=”../about/” />

    Thanks all, this topic is resolved.. kinda

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘custom .htaccess rewrite rules’ is closed to new replies.