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
-
Looking for list Pro's & Con's of removing Folder from URL?
Hi We have a sub-folder ("/shop-by-department/") which is pretty much useless on our site and I'm looking to remove it. But the team want a list of the Pro's & Con's in doing so. So for example I'll be changing www.example.ie/shop-by-department/furniture/beds/product-a to www.example.ie/furniture/beds/product-a I know there will be an intial hit as Google adjusts to the change but think it's definitely the way to go. I was lookng for a complete list of the Pro's & Con's to send onto the team. It'll be going to the traditional marketing (print, radio, etc.) too so can ve top-level points too. Hope you can help! Thanks
Web Design | | Frankie-BTDublin0 -
Is there a way to redirect URLs with a hash-bang (#!) format?
Hi Moz, I'm trying to redirect www.site.com/locations/#!city to www.site.com/locations/city. This seems difficult because anything after the hash character in the URL does not make it to the server thus cannot be parsed for rewriting. Is there an SEO friendly way to implement these redirects? Thanks for reading!
Web Design | | DA20130 -
How to bounce back after a new url & new site design?
About a month ago, my company changed domains (from the long-established www.imageworksstudio.com to the new www.imageworkscreative.com) and also did a complete overhaul of our site. We tried to do everything necessary to keep Google happy as we went through this change, but we've suffered a drastic loss of both rankings and traffic. I know that can happen as a result of a redesign AND as a result of a new domain, but I'm wondering how long you would expect it to take before we bounced back and also, what can we do in the meantime to improve?
Web Design | | ScottImageWorks0 -
My site build in HTML has been badly hit this recent update and I have been toying on the idea of changing it to Wordpress
My site build in HTML has been badly hit this recent update and I have been toying on the idea of changing it to Wordpress. Would this help in my rankings? It seems the hit came only that last 2-4 days when business become much quieter. Frankly i have no idea on why the site fell in ranking all of a sudden. Been comparing to competitors and even a friend in the same industry and nothing makes sense so far (link profile, DA, PA etc) This site has been ranking well for 3 years prior to this. 2. My site has loads of content and visitors arrive from various landpages. But by changing it wordpress, the url of most of them would probably change. What should i do? 301 redirect all of them or is there a better method?
Web Design | | rester0 -
Wordpress Frameworks for SEO - Genesis - Does it Get Any Better?
I'm sure there's a ton of people in this community running Wordpress, any Genesis developers/users out there? For anybody who doesn't know, Genesis is a parent framework for building wordpress child themes. It saves a ton of time for people that aren't too handy w/ php (like me). I'm working on a few sites locally with it right now, and it's really impressive. I'm seriously never planning on using another WP framework. It also integrates perfectly with Yoast SEO, which is something not all frameworks do. So I thought I'd try to get some input from the community here, anybody have another framework they like? Or have an opinion on the SEO benefit of genesis? Would love to hear...
Web Design | | SVmedia0 -
Google fails to pick out the correct URL of the story
Hi , I have a page with many news storeys on it. Google craws the page but it picks up a more general url even though I've embedded the direct URL within anchor tags around the headline . The snippet below got linked by Google to http://www.irishnews.com/ Any idea how i can get Google to pick-up http://www.irishnews.com/news.aspx?storyId=1180708 would be very welcome Peter Quinn: Family made scapegoats of financial crisis News Peter Quinn: Family made scapegoats of financial crisis THE Quinn family have been made scapegoats of the financial crisis surrounding the former Anglo Irish Bank, tycoon Sean Quinn's brother Peter claimed yesterday.Peter Quinn, a former president of the GAA, said hi read more»
Web Design | | Liammcmullen0 -
Javascript, PhP and SEO Impact?
What are the Pro's and Con's of using Java Script and PHP in a site when factoring in SEO?
Web Design | | bronxpad0 -
Using tables in html
I have a question about tables in html.I heard that you shouldnt use tables in html,you should should use css instead.Ive used free html templates that use tables but those tables are styled through css:td,th,table and other table elements are ale styled through css.I'm curious is this ok for SEO or should tables should be dropped altogether? Thanks for your response
Web Design | | PCTechGuy20120