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
-
Infinite Scroll and URL Changing
Hi, So my website is having an issue indexing. Much like other sports sites like ESPN or MLB or a variety of others my site changes the URL as you go down the page. So if you go on a news article and continue scrolling you'll go to another news article. I believe that this is creating errors in Search Console with the article being given an error of being "too long". I don't know how to keep this infinite scroll and url changing which increases my pageviews and eliminate the errors. Can someone help?
Web Design | | mattdinbrooklyn0 -
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 -
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 -
URL Structure
Hello, Within the last few months, my company launched a brand new website for our clients. Unfortunately, the web developers we went through aren't very knowledgeable on SEO practices and as a result, our URL structure is a total mess. I'm looking for some advice on the best way to go about a possible restructure of the URL's or what you suggest I should do from here. Any advice helps. Thanks! Lauren McLaughlin
Web Design | | LMcLaughlin0 -
Changing URL's for a website redesign
Hi folks, We're redesigning our website and looking for some advice on how changing our URL's would affected our rankings. If the page URLs are changing how can we carry out redirects to avoid losing any SEO rank? Thanks, Ross
Web Design | | Will_Craig0 -
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 -
Panda and Penquin Fall - Could HTML Design an Issue?
Hi, We were hit hard by Panda 3.4 on March 23rd 2012. Then Penguin came along and slapped us down a little farther on April 24th. White hat SEO for 13 years on the site. I have been trying to discover the reason we got hit so hard, to date 90% down. We ae wiped. I have a couple of keywords still #2 and #3 and we see up and down changes in Google webmaster tools, i.e. a keyword is supposedly up 50 points then another down 50. All other 150 keywords that we used to rank on the first page for are not even showing up. I have a person that is about to do a full link analysis but since we never went after links I just never had the feeling that is where our problem is at, but definitely going to explore it. The reason for my post is that last night I spoke with an SEO person that has some pretty good credentials (9 years experience and works currently at large online marketing company with seo with clients like Honda) and he was nice enough to just take a quick look at the site. He said he saw nothing really wrong and did not think that we were hit for any of the normal issues people are listing, i.e. duplicate content, backlinks. His first impression was that we were knocked down because the site is "hard to index". He said the site still uses tables and a lot of our Doc Statements were for HTML 4.01 from 1999. As we all know, there are 'many' experts in this industry. So I wanted a little feedback from the community. Our main site was built in Dreamweaver using tables. We do have a Wordpress blog that is very small and just now posting to add fresh content. (posts seem to rank pretty good, this is why I thought, you know he may be right) Would an older site be penalized like this for using tables? What would you do at this stage if you had a site that is not recovering? I have now reached panic mode and have to do something, just not sure of the next step. I will be happy to post the URL if anyone wants to help with advice. Thanks,
Web Design | | Force7
Force70 -
Effects of HTML layout on Arabic websites and SEO
Hi all, I was hoping someone may be able to help. We are putting together an Arabic website and due to reading right to left as opposed to left to right, the site HTML layout is mirrored compared to normal with everything flipped over. What we are wondering is, will this effect SEO and what are the SEO implications of this? Do the search engine bots automaticlaly know to read the content etc differently and understand that everything is purposely mirrored / the HTML is in a different location compared to a site in the UK / US etc? Any help on this would be most appreciated. Cheers!
Web Design | | marcelo-2753980