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
-
Does anyone know of an easy way to create jump links in WordPress without having to hardcode it into the HTML?
I am using Genesis Framework with the New Pro child theme on my site called Learn Internet Grow and when I create long articles I like to have a menu so readers can jump to a specific section. I wonder if there is a best practice for how to create jump links quickly without having to switch between the code editor and the post editor. There are a bunch of plugins but I am wary of adding more. Maybe if someone can tell me about one they had a good experience with. Ideally, a resource that shows you how to create a custom plugin for this or a non-plugin way to alter the framework to enable easy jump linking.
Web Design | | LearnInternetGrow0 -
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
Hi All, I have currently planning to do some url remapping on my Hire Website as alot of most important pages are far to many levels deep from the root domain. This is also making my sitemap not tidy etc. In GWT, Google knows that the theme is my website is Hire as it's the top word. Therefore do I still need to use the word hire in all my new url categories / structures or not ? Examples http://goo.gl/BFmvk2 I was thinking of remapping to www.xxxxxxx.xco.uk/tool-hire-birmingham http://goo.gl/pC9Bdp I was thinking of remapping to www.xxxxxx.co.uk/cleaning-equipment Notice in the later example , I do not have the word rent in the url. Any advice is much appreciated thanks peter
Web Design | | PeteC120 -
Site is getting crushed by spam traffic and Google Webmaster Tools giving crawl warnings. Also...
Currently hosting a site I'm planning on moving to a new server ASAP, 301 redirecting and have a domain that has nice authority and very old. On the current site I need to clean up the blog. I have a few questions actually.... 1. I'd like to remove most of the blog articles as I want the new site to be very high quality, but isn't it dangerous to do a 301 redirect to the same page for all these articles? 2. I want to focus on the new site as the current site has too many issues but still managing to hang in their. is highly outdated yet I don't want to spend a ton of time on the site before the 301 redirect. With the Pigeon and Panda 4.0 rumors being released soon, I want to get the new site completed ASAP. Do you think it's better if I fix the 3. Would removing cloudflare make things better or worse with the crashing of my site due to high traffic (mainly spam on the blog.) 4. My best article by far is outdated, but should I waste time updating it before redirecting or should I just get the new site going? I did way too many guest posts thinking content is king, but at least checked the outgoing links Domain Auth, Page Auth, and MozTrust in OSE, but first off I'm going to remove a page that mentions I'm looking for guest bloggers. I tried to keep the posts relevant but at the time you could get away with 5. Anything I can do to slow down these spammers on Wordpress? I noticed most of them are checking for vulnerabilities but I'm keeping it up to date, have caching setup. Thanks!
Web Design | | eugenecomputergeeks0 -
No cache meta tags - does it help Google get back and reindex faster?
I saw these meta tags on a site and am trying to figure out their benefit. These meta tags are on the home page, product pages, every page of the site. Will it cause search engine bots to come back and index pages faster? Will it cause slower page loading in browsers if nothing is cached? http-equiv="pragma" content="no-cache"/> http-equiv="cache-control" content="no-cache,no-store,must-revalidate"/> http-equiv="expires" content="0"/>
Web Design | | CFSSEO0 -
Pulling old site-map and URL structure of a site
Hey guys how do I pull an old sitemap or URL structure of a site ! This company I am helping out . Build a new site without any 301 redirect ! It's been about 2 months and hosting company sent me. SQL database file said we basically need to build another site ! Wondering if there are any other ways to see what exact urls were existent before their change over
Web Design | | BizDetox0 -
PHP Framework Question! Zend, CakePHP, Symfony, CodeIgniter. Finally I get to ask something.
Hey ya'll! We are looking to re-build our backoffice website. It's a dynamically generated site that pulls information from a DB. The DB is populated by the quote form. The DB contains the customers' info, shipping, email templates, and everything to process orders. The backoffice website is custom made in JAVA, but the owner is not happy with the programmer. I told the owner we may want to go to a PHP Framework. My question is which PHP framework would you recommend and why? Zend CakePHP Symfony CodeIgniter
Web Design | | Francisco_Meza0 -
The use of foreign characters and capital letters in URL's?
Hello all, We have 4 language domains for our website, and a number of our Spanish landing pages are written using Spanish characters - most notably: ñ and ó. We have done our research around the web and realised that many of the top competitors for keywords such as Diseño Web (web design) and Aplicaión iPhone (iphone application) DO NOT use these special chacracters in their URL structure. Here is an example of our URL's EX: http://www.twago.es/expert/Diseño-Web/Diseño-Web However when I simply copy paste a URL that contains a special character it is automatically translated and encoded. EX: http://www.twago.es/expert/Aplicación-iPhone/Aplicación-iPhone (When written out long had it appears: http://www.twago.es/expert/Aplicación-iPhone/Aplicación-iPhone My first question is, seeing how the overwhelming majority of website URL's DO NOT contain special characters (and even for Spanish/German characters these are simply written using the standard English latin alphabet) is there a negative effect on our SEO rankings/efforts because we are using special characters? When we write anchor text for backlinks to these pages we USE the special characteristics in the anchor text (so does most other competitors). Does the anchor text have to exactly I know most webbrowsers can understand the special characters, especially when returning search results to users that either type the special characters within their search query (or not). But we seem to think that if we were doing the right thing, then why does everyone else do it differently? My second question is the same, but focusing on the use of Capital letters in our URL structure. NOTE: When we do a broken link check with some link tools (such as xenu) the URL's that contain the special characters in Spanish are marked as "broken". Is this a related issue? Any help anyone could give us would be greatly appreciated! Thanks, David from twago
Web Design | | wdziedzic0 -
Is there any difference in using an underscore vs. a dash in the directory portion of the url?
A friend who is a software developer asked this question regarding the directory portion of the url: Is it better to use dashes or underscores? I know in the domain name Matt Cutts recommends dashes, but what about the directory extension?
Web Design | | RobertFisher0