How do you get rid of the .html and .php extensions at the end of urls?
-
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)
-
Yes the code would remain the same.
-
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] -
check the .htaccess file in your web host. And follow the Ryan comm.
-
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]
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
Migration from HTML to Wordpress - SEO Implications?
I am in the process of having a wordpress site developed to replace my current HTML site. (I currently have my website in html and a blog in wordpress in a sub directory). I am doing this in phases to try and preserve as much of my good rankings as possible. My first phase is to replicate my site with the exact same pages, meta data, and site structure. I'm hoping that google will see this as not much change and not change my rankings for the worse. I also made it a goal that my site speed tests be at least equal to what they are now. We will have to 301 all of the URLs however since it will be going from /example.html to /example. I believe my blog will also need to move into the root directory as well, so I need to 301 all of those pages. I plan to wait a couple months for Phase 2. Phase 2 involves replacing old content (photo galleries), and introducing new content (virtual tours, videos, new pages, etc.) One of my reasons for moving to wordpress is to keep up with current trends a little easier since I have very little time. (I am owner, website maintainer, SEO - all on my own). My question here is three parts. 1. Do you think this strategy will work to preserve my current rankings? 2. Do you have any lessons learned or advice to share with me to make this as smooth as possible? 3. Do I really need to wait to add new content? I might get antsy and want to do it sooner! 🙂 Thank you in advance!
Web Design | | CalicoKitty20001 -
Will interlinking using dynamic parameters in url help us in increasing our rankings
Hi, Will interlinking our internal pages using dynamic parameters(like abc.com/property-in-noida?source=footer) help us in increasing our rankings for linked pages OR we should use static urls for interlinking Regards
Web Design | | vivekrathore0 -
How do we get search engine bots to the item detail pages?
The problem we have is that we have lots of inventory pages. These inventory pages have a bunch of links at the top linking to different styles of the item, up to 56 links in some cases. Then each item listed has a link to the item's detail page and a link to the item's shop owner's page. So if a page has 50 items shown, there are really 100 links just for the inventory. This is not taking into account the header links, footer links, sidebar links to other sections on the site. We have all these links to help consumers move through the site. The problem is that every item detail page on the site is not getting indexed and actually I think it's more like over 50% of the item detail pages are not indexed because the search engines are too busy following all these other links. Should we nofollow, index the links to the different styles of the item, the shop owner page? Or what should we do to get the search engine bots to index our item detail pages?
Web Design | | CFSSEO0 -
Is it worth keeping .html even if 301'ing
We're going from static to a wordpress based ecommerce site. While we can append .html to urls the directory structure will change so that www.oursite.com/productname.html goes to www.oursite.com/product/productname.html My question is: Is it worth the trouble (from an seo perspective) of using a plugin to append new urls with .html when we're going to have to use 301 redirects anyway? If not should the urls have a trailing slash?
Web Design | | jbk3650 -
URL Designing and Site Architecture
Hi, 1. At the end of the URL, should we have "/" or not (for e.g. my website www.example.com/abc/) 2. What is the optimum level of site depth 3. Google crawler will go through the breadcrumb or url (If a page is at 6th level through breadcrumb and at 4th level through URL, at which level will google crawler recognize this.
Web Design | | adiez12340 -
Switching from HTML Static to WordPress Platform - SEO
Hi All, Hope everyone is doing well. I am currentyl in the process of having a re-design to myu HTML Static Site, I am switching to WordPress. My site is still running now until the new one is prepared. My question is: I do rank pretty well for some of our strong local keywords, we also have a FEW links pointing to inner pages with an extension of .HTML, should I set the the WordPress URL's to reflect .HTML or will the Search Enginesfigure out that http://www.domain/innerpage.html is the same as http://www.domain/innerpage/ or is it NOT the same. Should I switch or not? Thanks for your input Jimmy
Web Design | | jimmy02250 -
How important is URL length?
Is URL length really that important? I have many articles that would lose meaning if the URL was shortened and for most, they would have to be under the root domain instead of under the category in order to fit. Has anyone tested if they were negatively impacted by URL's that are too long?
Web Design | | HMCOE0 -
URL structure for multiple cities?
Hi, i am in the process of setting up a business directory site that will be used in a number of cities, though i am initially launching with only one city. My question is, what is the best URL structure to use for the site and should i start using this URL structure from day one? At the moment i am using www.mysite.com.au as my primary website where it contains all listings for the the one initial launch city. Though to plan for the future i was considering this URL structure: www.mysite.com.au/cityname so for example, if i launch in the city Sydney initially then all website traffic that goes to www.mysite.com.au would simply be redirected (302 temp redirect?) to www.mysite.com.au/sydney. When i expand to other cities www.mysite.com.au would simply be a "select your city" screen that then redirects to the city of choice (similar to www.groupon.com page). How would doing a 302 redirect from www.mysite.com.au to www.mysite.com.au/city impact on SEO for the initial launch? Or should i just place this on the root domain since no other cities exist at the moment?
Web Design | | adamkirk0