301 redirecting a .html to .php?

by 4 replies
5
I've search online and can't find the answer. I have a specific set of pages on my old site that use .html that I am trying to redirect to my new site which is now using .php.

I'm trying to use the following code in .htaccess:

Redirect 301 OldURL.html NewURL.php

But when I do that and test the redirect the new page comes up as URL.html.php

How do I redirect the .html page to .php?

Thanks,

BobbyG
#programming #301 #html #php #redirecting
  • you didn't search right maybe?

    found this in a few seconds
    webconfs.com/how-to-redirect-a-webpage.php/

    PHP Redirect
    Code:
    <?
    Header( "HTTP/1.1 301 Moved Permanently" ); 
    Header( "Location: http://www.new-url.com" ); 
    ?>
    And
    ndesign-studio.com/blog/301-htaccess-redirect

    To Redirect Certain Page(s):
    Code:
    Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
     Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
    To Redirect Entire Site:
    Code:
    Redirect 301 / http://www.new-site.com/
  • The first doesn't apply because I need to do it in the .htaccess file.

    The second is what I just stated I already tried and it adds .html.php to the new page.

    The third does not apply because I'm not redirecting the entire site.
  • Do you have any other code in the .htaccess file after the redirect?
    And did you notice how the redirect has the entire url and not just the new page?
    • [1] reply
    • That doesn't matter, redirects will work relative to the current protocol and hostname if it is not specified.
      This is the part that matters. Probably you're dealing with a conflict of some sort.

      If the .php pages all have the same names as their .html alternatives, you could try using "redirectmatch", which will work something like this:

      Code:
      RedirectMatch 301 ^/(.*)\.html$ http://example.com/$1.php
      One liners are always nicer than going through every single page on the site and redirecting. But again, this will only work if all the pages are named the same, other than the extension.

Next Topics on Trending Feed

  • 5

    I've search online and can't find the answer. I have a specific set of pages on my old site that use .html that I am trying to redirect to my new site which is now using .php. I'm trying to use the following code in .htaccess: