Skip to content
    Moz logo Menu open Menu close
    • Products
      • Moz Pro
      • Moz Pro Home
      • Moz Local
      • Moz Local Home
      • STAT
      • Moz API
      • Moz API Home
      • Compare SEO Products
      • Moz Data
    • Free SEO Tools
      • Domain Analysis
      • Keyword Explorer
      • Link Explorer
      • Competitive Research
      • MozBar
      • More Free SEO Tools
    • Learn SEO
      • Beginner's Guide to SEO
      • SEO Learning Center
      • Moz Academy
      • SEO Q&A
      • Webinars, Whitepapers, & Guides
    • Blog
    • Why Moz
      • Agency Solutions
      • Enterprise Solutions
      • Small Business Solutions
      • Case Studies
      • The Moz Story
      • New Releases
    • Log in
    • Log out
    • Products
      • Moz Pro

        Your all-in-one suite of SEO essentials.

      • Moz Local

        Raise your local SEO visibility with complete local SEO management.

      • STAT

        SERP tracking and analytics for enterprise SEO experts.

      • Moz API

        Power your SEO with our index of over 44 trillion links.

      • Compare SEO Products

        See which Moz SEO solution best meets your business needs.

      • Moz Data

        Power your SEO strategy & AI models with custom data solutions.

      NEW Keyword Suggestions by Topic
      Moz Pro

      NEW Keyword Suggestions by Topic

      Learn more
    • Free SEO Tools
      • Domain Analysis

        Get top competitive SEO metrics like DA, top pages and more.

      • Keyword Explorer

        Find traffic-driving keywords with our 1.25 billion+ keyword index.

      • Link Explorer

        Explore over 40 trillion links for powerful backlink data.

      • Competitive Research

        Uncover valuable insights on your organic search competitors.

      • MozBar

        See top SEO metrics for free as you browse the web.

      • More Free SEO Tools

        Explore all the free SEO tools Moz has to offer.

      What is your Brand Authority?
      Moz

      What is your Brand Authority?

      Check yours now
    • Learn SEO
      • Beginner's Guide to SEO

        The #1 most popular introduction to SEO, trusted by millions.

      • SEO Learning Center

        Broaden your knowledge with SEO resources for all skill levels.

      • On-Demand Webinars

        Learn modern SEO best practices from industry experts.

      • How-To Guides

        Step-by-step guides to search success from the authority on SEO.

      • Moz Academy

        Upskill and get certified with on-demand courses & certifications.

      • SEO Q&A

        Insights & discussions from an SEO community of 500,000+.

      Unlock flexible pricing & new endpoints
      Moz API

      Unlock flexible pricing & new endpoints

      Find your plan
    • Blog
    • Why Moz
      • Small Business Solutions

        Uncover insights to make smarter marketing decisions in less time.

      • Agency Solutions

        Earn & keep valuable clients with unparalleled data & insights.

      • Enterprise Solutions

        Gain a competitive edge in the ever-changing world of search.

      • The Moz Story

        Moz was the first & remains the most trusted SEO company.

      • Case Studies

        Explore how Moz drives ROI with a proven track record of success.

      • New Releases

        Get the scoop on the latest and greatest from Moz.

      Surface actionable competitive intel
      New Feature

      Surface actionable competitive intel

      Learn More
    • Log in
      • Moz Pro
      • Moz Local
      • Moz Local Dashboard
      • Moz API
      • Moz API Dashboard
      • Moz Academy
    • Avatar
      • Moz Home
      • Notifications
      • Account & Billing
      • Manage Users
      • Community Profile
      • My Q&A
      • My Videos
      • Log Out

    The Moz Q&A Forum

    • Forum
    • Questions
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

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

    1. Home
    2. SEO Tactics
    3. Technical SEO
    4. Converting files from .html to .php or editing .htaccess file

    Moz Q&A is closed.

    After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

    Converting files from .html to .php or editing .htaccess file

    Technical SEO
    7
    11
    5041
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with question management privileges can see it.
    • JohnHerrigel
      JohnHerrigel last edited by

      Good day all,

      I have a bunch of files that are .html and I want to add some .php to them.

      It seems my 2 options are

      1. Convert .html to .php and 301 redirect

      or

      1. add this line of code to my .htaccess file and keep all files that are .html as .html

      AddType application/x-httpd-php .html

      My gut is that the 2nd way is better so as  not alter any SEO rankings, but wanted to see if anybody had any experience with this line of code in their .htaccess file as definitely don't wan to mess up my entire site 🙂

      Thanks for any help!

      John

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

        Hi John

        The first line removes the extension

        The second line adds them back in a specific order IE you want PHP to execute first.

        If you got it going that is what counts.

        Good luck,

        Don

        1 Reply Last reply Reply Quote 1
        • JohnHerrigel
          JohnHerrigel @donford last edited by

          Thanks so much for this Don.. this is what I added that seemed to work for my server

          AddHandler application/x-httpd-php .html .htm

          As the AddType caused errors but doing  some further research I found the above code.

          I wonder if what you propose would accomplish what I did?

          Thanks and all the best,

          John

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

            Hi John,

            If the URL's are well indexed and doing well, you "may" not want to change the url. To simply add the ability to run php first you can do it very easily with just what you thought, .htaccess

            In fact when I took over as webmaster on my corporate site which was indexed very well I had to do just that.

            Add this to your .htaccess file:

            RemoveHandler .html .htm
            AddType application/x-httpd-php .php .htm .html

            JohnHerrigel 1 Reply Last reply Reply Quote 0
            • Highland
              Highland @JohnHerrigel last edited by

              If you really want to go this route, add this to your site .htaccess

              RewriteCond %{SCRIPT_FILENAME} !-d
              RewriteRule ^([^.]+)$ $1.html [NC,L]

              So domain.com/file will access file.html

              Again, the caveat is there is a short term SEO hit for doing this. Long term, you should be fine.

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

                This is a sweet idea.. any tutorial on this? How does it effect existing links directed at the .html and .php pages?

                Thanks Keri!

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

                  Have you considered just rewriting your URLs so they don't use extensions at all? That way, when you use a different technology, you don't need to rewrite your URLs once again. If you look at SEOmoz, you see they don't use .php or .html as extensions, but instead have no extensions.

                  JohnHerrigel 1 Reply Last reply Reply Quote 0
                  • jpgprinting
                    jpgprinting last edited by

                    I did option 1 on one of my websites some time ago and works fine, rankings are the same. Takes about 2 moth to get the same visits on all the links again.

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

                      We use the AddType function all the time when updating websites. It's far easier to do that that to recreate everything and redirect it.

                      It allows all of your internal navigation to remain as is and it keeps all of your inbound links from becoming redirected links. Also, remember that it has been announced that 301 redirected links lose value over time so this is another reason to not do it the hard way.

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

                        Just make sure that you don't redirect all HTML files.  I suspect that either way is equal.  What you are telling in either case i

                        "Hi Google we have moved but don't worry we have moved here"

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

                          I would pick #2, where you process .html files with PHP. Changing URLs involves taking a temporary SEO hit and I would not recommend doing it.

                          1 Reply Last reply Reply Quote 1
                          • 1 / 1
                          • First post
                            Last post

                          Got a burning SEO question?

                          Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


                          Start my free trial


                          Browse Questions

                          Explore more categories

                          • Moz Tools

                            Chat with the community about the Moz tools.

                          • SEO Tactics

                            Discuss the SEO process with fellow marketers

                          • Community

                            Discuss industry events, jobs, and news!

                          • Digital Marketing

                            Chat about tactics outside of SEO

                          • Research & Trends

                            Dive into research and trends in the search industry.

                          • Support

                            Connect on product support and feature requests.

                          • See all categories

                          Related Questions

                          • acktivate

                            Why add .html to WordPress pages?

                            A site I may take over has a plugin that adds .html to the pages. I searched online but I’ve only found how to add it rather than why to add it. Is it needed? If I remove it, I’ll have to be careful with SEO / indexed pages and redirects.  The site is running 3.x.x and 90% of the plugins have not been updated in over 5 years including this one. Before I update to 4.7.x, I am trying to understand the landscape (pros / cons) on why something could be used and if I need to find a suitable replacement for it.

                            Technical SEO | | acktivate
                            2
                          • Uber_

                            Add trailing slash after removing .html extention

                            My website is non www ,it has wordpress in subdirectory and some static webpages in the root and other subdirectory 1. i want to remove .html extention from the webpages in the root and
                            the others static webpages in subdirectory.
                            2. add slash at the end.
                            3. 301 redirect from non slash to url with slash. so it should be http://ghadaalsaman.com/articles.html to http://ghadaalsaman.com/articles/ and http://ghadaalsaman.com/en/poem-list.html to http://ghadaalsaman.com/en/poem-list/ the below code 1. working with non slash at the end **2. **redirect 301 url with slash to non here's my .htaccess <ifmodule mod_rewrite.c="">Options +FollowSymLinks -MultiViews RewriteEngine On
                            RewriteBase /</ifmodule> #removing trailing slash
                            RewriteCond %{REQUEST_FILENAME} !-d     
                            RewriteRule ^(.*)/$ $1 [R=301,L] #www to non
                            RewriteCond %{HTTP_HOST} ^www.(([a-z0-9_]+.)?domain.com)$ [NC]
                            RewriteRule .? http://%1%{REQUEST_URI} [R=301,L] #html
                            RewriteCond %{REQUEST_FILENAME} !-f
                            RewriteCond %{REQUEST_FILENAME} !-d
                            RewriteRule ^([^.]+)$ $1.html [NC,L] #index redirect
                            RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/
                            RewriteRule ^index.html$ http://ghadaalsaman.com/ [R=301,L]
                            RewriteCond %{THE_REQUEST} .html
                            RewriteRule ^(.*).html$ /$1 [R=301,L] PS everything is ok with the wordpress , the problems with static pages only. Thanks in advanced

                            Technical SEO | | Uber_
                            0
                          • kcb8178

                            Is there a limit to how many URLs you can put in a robots.txt file?

                            We have a site that has way too many urls caused by our crawlable faceted navigation.  We are trying to purge 90% of our urls from the indexes.  We put no index tags on the url combinations that we do no want indexed anymore, but it is taking google way too long to find the no index tags.  Meanwhile we are getting hit with excessive url warnings and have been it by Panda. Would it help speed the process of purging urls if we added the urls to the robots.txt file?  Could this cause any issues for us?  Could it have the opposite effect and block the crawler from finding the urls, but not purge them from the index? The list could be in excess of 100MM urls.

                            Technical SEO | | kcb8178
                            0
                          • NicDale

                            Is there any value in having a blank robots.txt file?

                            I've read an audit where the writer recommended creating and uploading a blank robots.txt file, there was no current file in place.  Is there any merit in having a blank robots.txt file? What is the minimum you would include in a basic robots.txt file?

                            Technical SEO | | NicDale
                            0
                          • BridgetGibbons

                            For an image which is in the CSS and not the HTML, can you add an alt tag?

                            I would like to improve SEO on a page with three big images, which are currently hosted in the CSS. The sample I am working with is at http://xquisitevents.com/about-us/ and I put my cursor over the big picture of the wedding dress with bouquet, I inspected the element and saw this code in a div tag: #upperleft { background-image:url(images/AboutTopLeft.jpg); Can I add an alt tag to the CSS somehow, or can I have it added to the HTML? What is the best way to handle this, to include keywords like exquisite weddings and special event designs?

                            Technical SEO | | BridgetGibbons
                            0
                          • Nightwing

                            Does Bing ignore robots txt files?

                            Bonjour from "Its a miracle is not raining" Wetherby Uk 🙂 Ok here goes... Why despite a robots text file excluding indexing to site http://lewispr.netconstruct-preview.co.uk/ is the site url being indexed in Bing bit not Google? Does bing ignore robots text files or is there something missing from http://lewispr.netconstruct-preview.co.uk/robots.txt I need to add to stop bing indexing a preview site as illustrated below. http://i216.photobucket.com/albums/cc53/zymurgy_bucket/preview-bing-indexed.jpg Any insights welcome 🙂

                            Technical SEO | | Nightwing
                            0
                          • bimmer540

                            A script to automatically write 301 redirect rules to htaccess?

                            I was wondering if anyone could help provide some resources on how to automatically write 301 redirect rules to htaccess.  Allow me to explain... I'm building a new website and the primary users are businesses.  They have their own profile pages on the site. The URL is based off of their Company Name. In the event that they decided to change their name... reasons being, perhaps they mispelled it the first time, or they're removing LLC or adding Inc, I want to also change the URL and redirect the old URL to the new URL. Since the URL is based off of their Company Name, making a change to the company name would make a change to the URL.  I know it doesn't have to work this way, but for our purpose this works best. In case the old URL had any links to it, I wanted to see if there was an way to automatically update an htaccess file with a 301 redirect from the old URL to the new one. Could anyone point me in the right direction of how to do this?  Perhaps a sample script.  I've done a lot of searches on Google and can't seem to find anything. e.g. Original:
                            Name:  XYZ Widgets
                            URL:  website.com/xyz-widgets New - business changes their company name in their profile:
                            Name:  XYZ Widgets, Inc.
                            URL:  website.com/xyz-widgets-inc Upon the user saving the changes in their profile, I'd like to write a 301 redirect to an htaccess file:
                            Redirect 301 /xyz-widgets http://www.website.com/xyz-widgets-inc I know how to manually write redirects and I've got a pretty smart web developer.  We've just never triggered a script to automatically write to an htaccess file before. Is this possible?  Any resources are appreciated.  Any security risks? Thanks!

                            Technical SEO | | bimmer540
                            0
                          • NaescentAdam

                            Index.php and 301 redirect with Joomla

                            Hi, I'm running Joomla 1.7 with SEF on and I'm trying to do a htaccess redirect which fails. I have approximately 100 in effect so far and all working fine, but I have one snag. Index.php is not working as I need it to when it's redirected to www.myurl.com/ If I turn on index.php redirect to root using this code #index.php to root
                            RewriteCond %{HTTP_HOST} ^myurl.com$ [OR]
                            RewriteCond %{HTTP_HOST} ^www.myurl.com$
                            RewriteRule ^index.php$ "http://www.myurl.com/" [R=301,L] And then go to www.myurl.com/test.html I'm redirected to the homepage. I think this is because all pages are index.php in joomla. SEOMOZ and Google both think that index.php and root are duplicate pages. Does anyone have any advice for overcoming this? Thanks, Adam

                            Technical SEO | | NaescentAdam
                            0

                          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
                          Free SEO Tools
                          • Domain Authority Checker
                          • Link Explorer
                          • Keyword Explorer
                          • Competitive Research
                          • Brand Authority 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 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
                          • Accessibility
                          • Terms of Use
                          • Privacy

                          Looks like your connection to Moz was lost, please wait while we try to reconnect.