How to Do a 301 Redirect in htaccess

For years my website homepage was with the homepage being an index.htm file. I just converted the homepage to a WP site that I intend to make into a multisite. I am trying to add a line in the htaccess file to create a 301 redirect to redirect from to or whatever will cause the redirect. I've tried the following lines of code without success:

RewriteRule ^index\.htm$ [R=301]

RewriteRule ^index\.htm$ [R=301]

Redirect 301 /index.htm

Each time I put in the browser I am taken to the new WP site, but it says the page cannot be found.

What is the code to redirect the index.htm file to the WordPress site home page?


  • 3SixtyEvolve
    • New Recruit

    Hi @RKeyt

    Welcome to WPMU DEV and thank you for being a member!

    Please try this:
    Redirect One File Extension to Another
    Example of code to be used in the .htaccess file

    RedirectMatch 301 (.*)\.html$$1.php

    - The above code is used to 301 redirect one file extension to another. This is useful if you just change your file extensions for your web pages and keep the same URL structure.
    - This piece of the code html is the file extension you want to redirect.
    - This piece of the code is the domain name where the web pages are located.
    - This piece of the code php is the actual file extension your redirecting to.
    - The above code redirects all *.html requests to *.php and should be inserted into your root directories .htaccess file.

    Hope this information is helpful. Let me know if you managed to redirect. And once again, welcome to our Community - glad to have you!

    Have a good day!


  • RKeyt
    • New Recruit

    Thanks GinB, but I don't want to redirect files by file extension. I want to redirect from one URL to a different URL.

    Maybe the first question I need answered is do I or should I redirect the old index.htm file to the WordPress equivalent file? If Google or a site that links to tries to access this URL they get a page not found message on a blank WP page. I would like search engines and anybody else who goes to that specific URL to be redirected to the WP home page, but I cannot figure out how to write the line of code in htaccess.

    If somebody uses the link it does go into the WP homepage properly.

    I installed Redirection and tried several different redirects, but none worked. I was also not able to tell Redirection to write directly to the htaccess file because Redirection said it did not have the username and password to write to the file.

  • 3SixtyEvolve
    • New Recruit

    Hi @RKeyt

    Hope you're well.

    I offered this option since you wanted to redirect the index.htm to the index.php. Exactly the same URL's, but different file extensions.

    If the URL's were different, for instance to then you would be able to do a redirect from one web page to another one.

    I will add the redirect in any case for your reference :slight_smile:

    Redirect 301 /webpage.html

    - The above code is used to 301 redirect one web page to another.
    - The piece of code /webpage.html/ is the old web page.
    - The piece of code is the URL to the new web page. You can add directories to the piece of code /webpage.html/ if that's where the web page is located.
    - This should be added to the root directory .htaccess file.

    Please let me know if you get sorted.

    Have a good day!


  • aecnu
    • WP Unicorn

    Greetings RKeyt,

    Just checking if this issue was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

    If so, no need to reply, that's great news.

    If not, or you have any more questions related to this thread, please feel free to post them below including any new symptoms or errors and tick the 'Mark as Not Resolved (re-open)' box below the post area (or else we'll miss it!)

    Otherwise, happy days, glad you got it sorted :slight_smile:

    Thank you for being a WPMU Dev member!

    Cheers, Joe

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.