301 redirecting a .html to .php?

4 replies
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
#301 #html #php #redirecting
  • Profile picture of the author Cram
    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/
    {{ DiscussionBoard.errors[6719783].message }}
  • Profile picture of the author BobbyGeneric
    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.
    {{ DiscussionBoard.errors[6719810].message }}
  • Profile picture of the author KirkMcD
    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?
    {{ DiscussionBoard.errors[6721696].message }}
    • Profile picture of the author wayfarer
      Originally Posted by KirkMcD View Post

      And did you notice how the redirect has the entire url and not just the new page?
      That doesn't matter, redirects will work relative to the current protocol and hostname if it is not specified.
      Originally Posted by KirkMcD View Post

      Do you have any other code in the .htaccess file after the redirect?
      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.
      Signature
      I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs
      {{ DiscussionBoard.errors[6721783].message }}

Trending Topics