Have a question on 301 redirects

by pts123
15 replies
I have a wordpress site that I would like to convert to a html site...and I would like to know how I could create the proper 301 redirect in .htacces so that all .php posts pages point to the new html pages, within the same domain.

any suggestions would be very much appreciated.
#301 #question #redirects
  • Profile picture of the author Bruce Hearder
    Is there anything destinctive about the pages you wish to redirect.
    Are they anything like www.yourdomain.com?p=123 or are they broken up by categories etc.

    Its all depends on your permalink settings.

    Sorry i can't hep you more..

    Bruce
    {{ DiscussionBoard.errors[1079573].message }}
    • Profile picture of the author pts123
      Originally Posted by Bruce Hearder View Post

      Is there anything destinctive about the pages you wish to redirect.
      Are they anything like www.yourdomain.com?p=123 or are they broken up by categories etc.

      Its all depends on your permalink settings.

      Sorry i can't hep you more..

      Bruce
      There are no categories, just a series of post pages permalink structure is %postname%.php....

      I know that Host Gator has a redirect section , in which I once used to point a few stranded pages back to my site when I re-vamped one of my html sites...but it was only 2 pages that I needed to redirect...

      The idea I have for my current situation ( since my knowledge is limited in regards to htacces 301 redirects) would be to save all urls from the original site and then delete the word press files completely. Create and upload the new html files and then go to the redirect section in Hostgator and add each url from the old site individually to be repointed to the new html urls.....

      I suppose I could do this, but I have over 75 pages to redirect....I'm sure there is a more practical way , but I just don't know how to do it properly with a global 301 redirect code....

      I have read quite a bit on 301 redirects before I posted this question, but it seems there are always details missing that I need, most of these guys don't explain things for the layman...

      anyway if all else fails, I'll try to do it the long way, but it would be nice if I could take care of the whole thing through .htaccess as there are other sites that I would like to convert as well...
      {{ DiscussionBoard.errors[1080090].message }}
      • Profile picture of the author Steve Diamond
        Hi. I found a very practical resource for .htaccess and mod_rewrite that answers your question and many others about common usage situations.

        Here's the part that pertains to your question. This assumes that you want any arbitrary filename on your site the-post-name.php redirected to the-post-name.html. Put this in your .htaccess file:

        Code:
        Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /
        RewriteRule ^(.*).php$ /$1.html [R=301,L]
        Steve
        Signature
        Mindfulness training & coaching online
        Reduce stress | Stay focused | Keep positive and balanced
        {{ DiscussionBoard.errors[1080292].message }}
        • Profile picture of the author pts123
          Originally Posted by Steve Diamond View Post

          Hi. I found a very practical resource for .htaccess and mod_rewrite that answers your question and many others about common usage situations.

          Here's the part that pertains to your question. This assumes that you want any arbitrary filename on your site the-post-name.php redirected to the-post-name.html. Put this in your .htaccess file:

          Code:
          Options +FollowSymLinks
          RewriteEngine On
          RewriteBase /
          RewriteRule ^(.*).php$ /$1.html [R=301,L]
          Steve
          Hey Thanks for that ! So that is all I have to put in the .htaccsess ? and that will take care of everything ?

          sorry for the repetative questions ... I'm new to this stuff
          {{ DiscussionBoard.errors[1080470].message }}
          • Profile picture of the author Steve Diamond
            Originally Posted by pts123 View Post

            Hey Thanks for that ! So that is all I have to put in the .htaccsess ? and that will take care of everything ?

            sorry for the repetative questions ... I'm new to this stuff
            Yes, that's it. Now, let me add a few details, since you are new to this.

            One, this assumes that for each valid URL you currently have that ends in .php, you're going to create an html file with the same name that will be accessible at the same URL except that it ends in .html. So if the following are currently valid URLs on your site:
            • http://www.yourdomain.com/post-name-one.php
            • http://www.yourdomain.com/post-name-two.php
            • http://www.yourdomain.com/post-name-three.php

            You will be creating separate .html files which will be accessible with the following URLs:
            • http://www.yourdomain.com/post-name-one.html
            • http://www.yourdomain.com/post-name-two.html
            • http://www.yourdomain.com/post-name-three.html

            Two, you don't want to add that code to your .htaccess file until after you've created and uploaded those html files and verified that the URLs work as expected.

            Steve
            Signature
            Mindfulness training & coaching online
            Reduce stress | Stay focused | Keep positive and balanced
            {{ DiscussionBoard.errors[1081177].message }}
            • Profile picture of the author pts123
              Thank you very much for that...I have spent many hours over the last few days trying to figure all this out...

              this is a really big help...

              thanks again !!
              {{ DiscussionBoard.errors[1081197].message }}
              • Profile picture of the author pts123
                Hi Steve...

                I just thought of this...Would the redirects affect my back links to the site ? suppose my back links were pointing to mysite.com/post.php...would they still transfer over to the html version ? ...just curious

                One other question if I may,

                If I wanted to convert an html site to a Wordpress site, do I just switch around the .php with the .html ?

                Like this below:


                Options +FollowSymLinks
                RewriteEngine On
                RewriteBase /
                RewriteRule ^(.*).html$ /$1.php [R=301,L]

                as opposed to this below:

                Options +FollowSymLinks
                RewriteEngine On
                RewriteBase /
                RewriteRule ^(.*).php$ /$1.html [R=301,L]

                thanks for you help
                {{ DiscussionBoard.errors[1083319].message }}
                • Profile picture of the author Steve Diamond
                  Your backlinks will still work and will still count for SEO purposes. That's one of the best reasons for using 301 redirects in a case like this.

                  Yes, you could go the other direction (from html to php) by rewriting the code like that.

                  Steve
                  Signature
                  Mindfulness training & coaching online
                  Reduce stress | Stay focused | Keep positive and balanced
                  {{ DiscussionBoard.errors[1083588].message }}
                  • Profile picture of the author pts123
                    Thanks again, you have been a great help....
                    {{ DiscussionBoard.errors[1083808].message }}
                    • Profile picture of the author pts123
                      Hi Steve,

                      I did a test with the 301 redirect in .htaccess with an old blog that i don't use...I first uninstalled the wordpress theme through Fantastico and then proceeded to upload the new html files making sure that all html urls were identical to the old .php extensions...and then I uploaded the .htaccess file , but when when I did a test, I got a Server error 500

                      I rechecked to see if the .htaccess was good and I could find no errors ...so I don't know what happened...I'm using Host Gator so they support Apache...oh well

                      I removed the .htaccess file from my directory and the new html version showed up from the serps...

                      I'm glad I did a test on an unimportant site, otherwise, reconstructing my wordpress site would have been a real pain...

                      anyway back to the drawing board for me
                      {{ DiscussionBoard.errors[1084115].message }}
                      • Profile picture of the author Steve Diamond
                        No, don't give up yet. There's something about that .htaccess code that Host Gator's configuration for mod_rewrite doesn't like. That's all error 500 means. It should be fixable. Let me try an experiment and get back to you.

                        Steve
                        Signature
                        Mindfulness training & coaching online
                        Reduce stress | Stay focused | Keep positive and balanced
                        {{ DiscussionBoard.errors[1084408].message }}
                        • Profile picture of the author pts123
                          I really appreciate all your help..
                          {{ DiscussionBoard.errors[1084455].message }}
                        • Profile picture of the author Steve Diamond
                          Well, it works perfectly on one of my Host Gator sites. Is your .htaccess file in your public_html folder? Is this the only content in your .htaccess file? (You say you checked it, but did you copy and paste it?)
                          Code:
                          Options +FollowSymLinks
                          RewriteEngine On
                          RewriteBase /
                          RewriteRule ^(.*).php$ /$1.html [R=301,L]
                          If so, I can't explain why your Host Gator account should behave any differently from mine. I'd advise contacting Host Gator support.

                          Steve
                          Signature
                          Mindfulness training & coaching online
                          Reduce stress | Stay focused | Keep positive and balanced
                          {{ DiscussionBoard.errors[1084471].message }}
                          • Profile picture of the author pts123
                            Hi Steve, I figured it out....

                            There were 2 errors on my part, first of all I had saved the .htaccess file under txt. and not under "All Files" from my note pad...

                            2nd mistake was that my file extensions are htm and not html....for some reason my default settings in Dream Weaver were set to htm. which I don't normally do...but I just whipped up a quick template to make my test with...I just switched the html to htm in the redirect code..and everything works like a charm !

                            I just wish those guys in the Google webmaster forum were as helpful as you were...my questions were totally ignored over there..

                            Again I must thank you one more time, because of your help , I just made a huge advancement with what I needed to do

                            take care and have a great day !
                            {{ DiscussionBoard.errors[1084732].message }}

Trending Topics