.htaccess redirect from static site to Wordpress

Posted on 2009-04-15
Last Modified: 2012-05-06
I'm trying to redirect pages from an old static site to new pages in WordPress. So, for example,

should redirect to:

I'm using the following in the .htaccess file, but it's not working:

redirect 301 /mysite/contact.htm

Question by:carrboro
    LVL 50

    Expert Comment

    by:Steve Bink
    When you say "not working", what gives you that impression?  I mean, aside from not seeing the new page.  Are you receiving any error messages?  Have you examined the request/response conversation?
    LVL 7

    Expert Comment

    I would do it with Apache's URL Rewriting engine.

    - be sure to have the rewrite_module enabled (via : a2enmod rewrite)
    - in your site configuration (or local .htaccess), add something like :
            RewriteEngine On
            RewriteRule ^

    I hope this helps


    Author Comment

    By not working I mean the old URLs are still resolving to the old, static HTML pages rather than the new WordPress pages.

    I tried the rewrite above, but that is not working either. Here is what my current .htaccess file looks like. Note that I have WordPress in its own /blog directory and am using a page, rather than the blog, as my home page.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # END WordPress
    RewriteCond %{HTTP_HOST} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^.*$ "http\:\/\/www\.jeffthomascobb\.com\/blog" [R=301,L]
    LVL 7

    Expert Comment

    No need to add RewretiEngine on as it's already done

    Have you done several tests with my RewriteRule thing ? I think the I remember the sequence is important - you should check on apache2 official web site :

    => did you try it right after the "RewriteEngine On" line ?
    LVL 26

    Expert Comment

    Your 301 RewriteRule doesn't look right to me. I think it should be

    RewriteRule ^(.*)$$1 [R=301,L]

    Also, I think you want an [NC] at the end of your last RewriteCond so that the rule takes effect regardless of the case in the browser address bar. Otherwise, only will be redirected., etc. won't.

    Author Comment

    None of the above is working. I really don't want to change the Rewrite rule as souseran suggests, as that Rewrite has been working fine. It was in place before the changes that led to this question.

    I have tried the putting the Rewrite after Rewrite on, and that makes no difference. I have also checked to order.

    I am not actually clear why Rewrite would be the correct approach in the first place, given that what I am trying to redirect is static HTML pages, whereas Rewrite - at least as I understand it - tends to apply when the pages to be redirected are dynamic. Regardless, it seems to me this should not be terribly complicated. Someone must know the right approach to this.

    Accepted Solution

    I ended up figuring this out myself and implemented as a series of rewrites along the lines of:

    RewriteCond %{HTTP_HOST} ^$ [OR]
    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^contact\.htm$ "http\:\/\/www\.jeffthomascobb\.com\/contact\/" [R=301,L]


    Works fine now

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Wordpress Horizontal Drop-Down Menu In this tutorial I will show you had to add a WordPress horizontal navigation menu to your theme. I have searched and searched for a good tutorial on creating a WordPress nav menu without adding a plug-in or us…
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
    The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Click on Too…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now