The Moz Q&A Forum

    • Forum
    • Questions
    • My Q&A
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. SEO and Digital Marketing Q&A Forum
    2. Categories
    3. Technical SEO Issues
    4. Php to html - change in extension

    Php to html - change in extension

    Technical SEO Issues
    9 4 1.5k
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • seoug_2005
      seoug_2005 last edited by

      Hello, What is the code to redirect all the pages of a site from .php to .html extension? Thanks

      1 Reply Last reply Reply Quote 1
      • DanHill
        DanHill last edited by

        Add into your htaccess file :

        RewriteEngine on
        RewriteBase /
        RewriteRule ^(.*).html$ $1.php [L]

        Remember you'll need to make sure to change all the links on your site, and all external links too.

        The only other way around changing all the links would be to do 301 redirects for each URL which is, in my opinion not really worth all the work involved since .php and .html should both rank equally in Google and other search engines.

        seoug_2005 1 Reply Last reply Reply Quote 0
        • seoug_2005
          seoug_2005 @DanHill last edited by

          Thanks Daniel.

          "Remember you'll need to make sure to change all the links on your site, and all external links too."

          1. Do you mean i will have to manually change all the internal links on the site ?

          Shall i have to do this in the reverse case too ? For example changing  html to php ?

          2. For external links, should i contact the webmasters of the site linking to me ?

          DanHill deltasystems seoug_2005 4 Replies Last reply Reply Quote 0
          • DanHill
            DanHill @seoug_2005 last edited by

            1. Yes since the code I gave you will rewrite the extension of every single page FROM php to html.  From html to php would mean the same thing, since a link pointing to products.php would no longer work.  The rewrite only rewrites the extensions and not the links.

            2. Yes contacting the webmasters and changing the links would be better than doing 301 redirects of all your pages.

            I advise to test this on a testing server first, especially if your site has a lot of pages.

            1 Reply Last reply Reply Quote 0
            • deltasystems
              deltasystems @seoug_2005 last edited by

              Atul,

              You definitely don't need to contact webmasters to change any links.

              There is a 301 redirect flag you can apply to your rewrite rule:

              RewriteRule ^(.*).html$ $1.php [R=301,L]

              Do a 301 redirect test to confirm. Best of luck!

              1 Reply Last reply Reply Quote 0
              • KeriMorgret
                KeriMorgret last edited by

                I'd suggest that if you can to not use any extension in the displayed URLs. That way the next time you change languages the URL won't change. As an example, see the SEOmoz URLs -- it's just http://www.seomoz.org/q/php-to-html-change-in-extension with no extension.

                I don't know the code offhand for that, but I'm sure others can help you out with that.

                seoug_2005 1 Reply Last reply Reply Quote 1
                • seoug_2005
                  seoug_2005 @seoug_2005 last edited by

                  Thanks a lot daniel for your advice.

                  1 Reply Last reply Reply Quote 0
                  • seoug_2005
                    seoug_2005 @seoug_2005 last edited by

                    Hello Zachary,

                    Where should i enter the line mentioned by you ? After the code provided by Daniel ?

                    Will it redirect all the external links ?

                    1 Reply Last reply Reply Quote 0
                    • seoug_2005
                      seoug_2005 @KeriMorgret last edited by

                      I agree with you not to use any extension and will be looking for a code for this purpose.

                      1 Reply Last reply Reply Quote 0
                      • 1 / 1
                      • First post
                        Last post
                      • Html extensions
                        JohnSammon
                        JohnSammon
                        0
                        5
                        65

                      • SEO changing from Wix Flash too Wix HTML
                        GeoffKenyon
                        GeoffKenyon
                        0
                        2
                        179

                      • Site rebuild without HTML extension = broken links?
                        JarnoNijzing
                        JarnoNijzing
                        0
                        3
                        425

                      • Do index.php extensions count as duplicate content on Joomla sites?
                        AdeLewis
                        AdeLewis
                        0
                        3
                        2.1k

                      • HTML 5 and SEO any one seen any change ?
                        AlanMosley
                        AlanMosley
                        0
                        2
                        578

                      • Converting files from .html to .php or editing .htaccess file
                        donford
                        donford
                        0
                        11
                        3.6k

                      • Domain extension is a ranking factor? Does it change de value of my SEO
                        JeremyNelson58
                        JeremyNelson58
                        0
                        2
                        948

                      • URLs: To Change or Not to Change
                        94501
                        94501
                        0
                        8
                        1.2k

                      Get started with Moz Pro!

                      Unlock the power of advanced SEO tools and data-driven insights.

                      Start my free trial
                      Products
                      • Moz Pro
                      • Moz Local
                      • Moz API
                      • Moz Data
                      • STAT
                      • Product Updates
                      Moz Solutions
                      • SMB Solutions
                      • Agency Solutions
                      • Enterprise Solutions
                      • Digital Marketers
                      Free SEO Tools
                      • Domain Authority Checker
                      • Link Explorer
                      • Keyword Explorer
                      • Competitive Research
                      • Brand Authority Checker
                      • Local Citation Checker
                      • MozBar Extension
                      • MozCast
                      Resources
                      • Blog
                      • SEO Learning Center
                      • Help Hub
                      • Beginner's Guide to SEO
                      • How-to Guides
                      • Moz Academy
                      • API Docs
                      About Moz
                      • About
                      • Team
                      • Careers
                      • Contact
                      Why Moz
                      • Case Studies
                      • Testimonials
                      Get Involved
                      • Become an Affiliate
                      • MozCon
                      • Webinars
                      • Practical Marketer Series
                      • MozPod
                      Connect with us

                      Contact the Help team

                      Join our newsletter
                      Moz logo
                      © 2021 - 2026 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                      • Accessibility
                      • Terms of Use
                      • Privacy