Redirect all html -> php and more..

5 replies
Warriors,

I am in the middle of changing over to php (at last). I have done some reseach but before I go ahead just wanted to check. I am going to edit the htaccess file with this:

RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

any comment on this?

The domain is actually an addon domain in hostgator, just checking that this should not matter, I think I just need to create htaccess and put in the root of the addon?

The main domain is also changing:

However a little more complicated

I have also changed from html -> php but ALSO changed a whole bunch of files to another directory.

Now I want to do two things:

1) redirect to php
2) for 20+ pages change the path

Can I therefore use above redirect from html to php, and then I guess I will have to add each page 301 thats changed directory?

eg. ww..home.com/help-me-please.html
to: ww..home.com/articles/help-me-please.php

Also wanted to put in a 404 redirect to a page incase I missed anything, being the main domain how can I say

any 404 from ww..home.com -> new
but not to include any addon domains 404's

Q - do I need a htaccess file then on each addon domain - as I think the current main htaccess covers all domains at the moment?

hope that made sense

Your help is much appreciated

Jason
#html #php #redirect
  • Profile picture of the author Jason Brown
    Please......

    getting paranoid I did not ask the right question. Also nervous about switching over so any comments welcome.

    Many Thanks
    Jason
    {{ DiscussionBoard.errors[88677].message }}
  • Profile picture of the author rwil02
    I'm REALLY not an HTACCESS expert, but I think you could do the following:

    RedirectMatch 301 (.*)\.html$ http://www.example.com$1.php

    triggers the first redirect.

    Then list the 20 or so pages under that

    RedirectMatch 301 ^/mypage1.php$ http://www.example.com/articles/mypage1.php
    RedirectMatch 301 ^/mypage2.php$ http://www.example.com/articles/mypage2.php
    Signature

    Roger Willcocks
    L-Space Design
    Please vote to help me win a 3kW solar array

    {{ DiscussionBoard.errors[88717].message }}
    • Profile picture of the author edynas
      Banned
      maybe a silly question...The content you made till now...is there a reason why you switch it to .php because if it's purely because the rest is also I would leave it as is. you can mix .php and .html as much as you want on a site and there is no need to have it match.

      But if you do want it for estatic purposes (and not because you are using some sort of templet system now fi) you can also add these lines in the htaccess which will leave your .html on the surface the same but they will be .php files

      RewriteEngine on
      RewriteRule (.*).html $1.php

      I don't like to mess with structure after a site is indexed and rather build futher then to erase and start again. Even with a 301 redirect...it just scares me to do anything like that.
      {{ DiscussionBoard.errors[88802].message }}
      • Profile picture of the author Jason Brown
        Thanks for your replys guys.

        Its a total overhaul of an old html layout to a new and shiny CSS template - looks 100x better and will definitly help conversion.

        Got fed up with editing lots of pages for a small change which PHP will solve.

        I'm keeping all the txt the same, adding in some internal linking and a few other changes so should not be too bad.

        Thanks again.

        If it doesnt work I'll be back asking how to fix

        Cheers
        {{ DiscussionBoard.errors[91656].message }}
        • Profile picture of the author ChristianM
          Hi, you've probably got this sorted but just in case this helps anyone - I've attached a file which includes a .htaccess and a .php file - the htaccess sets the php file as the 404 page and whenever there is a 404 error the php file will check if a page by the same name but with a different file extension exists. It will then redirect so if you forget any redirects this might help.
          {{ DiscussionBoard.errors[136239].message }}

Trending Topics