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. Web Design
    4. How do you get rid of the .html and .php extensions at the end of urls?

    How do you get rid of the .html and .php extensions at the end of urls?

    Web Design
    5 3 4.1k
    • 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.
    • Ryan-Bradley
      Ryan-Bradley last edited by

      What is the whitehat way to properly remove the .html and .php extensions at the end of urls?

      Example:

      http://www.seomoz.org/learn-seo.php

      should be (and is)

      http://www.seomoz.org/learn-seo

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

        There are a few ways to do it and it depends on your server setup. Since you are showing a .php example I'll take a guess that you are using an Apache server. If that is the case the easiest method is to modify your .htaccess file.

        CAUTION: any mistake in your .htaccess file can cause your site to become instantly unavailable or have other negative effects. Always make a backup first. If you are not very confident in your abilities to make the change and you are on managed hosting, ask your host to make the change.

        The below code will remove the php extension from file names:

        RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]

        You can change the last line from php to html to have the effect for html extensions. Example:

        RewriteRule ^([^\.]+)$ $1.html [NC,L]

        Ryan-Bradley 1 Reply Last reply Reply Quote 4
        • augustos
          augustos last edited by

          check the .htaccess file in your web host. And follow the Ryan comm.

          1 Reply Last reply Reply Quote 0
          • Ryan-Bradley
            Ryan-Bradley @RyanKent last edited by

            Would it still be the same code if you had other code in the htaccess as well?

            For example my htaccess now looks like:

            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^([^.]+)$ $1.php [NC,L]

            RewriteEngine on
            RewriteCond %{HTTP_HOST} ^domain.com [NC]
            RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

            RyanKent 1 Reply Last reply Reply Quote 0
            • RyanKent
              RyanKent @Ryan-Bradley last edited by

              Yes the code would remain the same.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              • Does redirecting the existing URLs in the website without reducing our current rankings? The new website runs on the bubble, so it seems there is no provisions to redirect the existing URLs to this platform?
                0
                1
                51

              • Analytics year to year comparisons when Url extensions change?
                TrentonGreener
                TrentonGreener
                0
                2
                206

              • Help with error: Not Found The requested URL /java/backlinker.php was not found on this server.
                webmethod
                webmethod
                0
                5
                1.7k

              • URL Re-Mapping Question ?. Do I need to the theme of my business in my url struture even though GWT knows what my site is about
                PeteC12
                PeteC12
                0
                3
                49

              • Is it bad to have /index.php at the end of a uri?
                CleverPhD
                CleverPhD
                0
                7
                1.9k

              • Will changing our URL's to MVC friendly URL's have a positive or negative affect on our rankings and link juice?
                SanketPatel
                SanketPatel
                0
                2
                308

              • Url structure
                BryanCasson
                BryanCasson
                0
                3
                743

              • SEOMoz crawl report shows a duplicate content and duplicate title for these two url's http://freightmonster.com/ and http://freightmonster.com/index.html. How do I fix this?
                Smith-Digital
                Smith-Digital
                1
                3
                610

              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