What is the code to 301 http to www in htaccess file on unix server
-
i want to 301 my http home page to www on a linux server and all my other redirects are set up similar to this in my htaccess file:
redirect 301 /example-page.html http://www.example-page.html
how do I 301 redirect:
http://example.com to http://www.example.com
I've tried all kinds of code recommended for an htaccess file on a linux server and nothing seems to work.
Thanks for the help mozzers!
Ron
-
1st works fine for me....
Redirect 301 /tags/xp/ http://www.test.com/tags/windows-xp/
if it is not working there must be some other problem!
-
Hi Ron,
You will need to use URL rewrite and the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !=www.example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]That will redirect any page/file on example.com/file to www.example.com/file with a 301 redirect.
Hope that helps!
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
-
Help, site traffic has dropped significantly since we changed from http to https
Heya, so I am just in charge of the content on the site, and the SEO content, not the actual back-end stuff. A little under 2 weeks ago we switched to https, and our site traffic has been down a lot ever since. When I SERP check our keywords, they don't seem to have dropped in rankings pages. Here is what I got when I asked our dev guy if 301 redirects were put in: I did not add any redirects so all of the content is accessible on both unless individual links get hardcoded one way or the other. The only thing in place is a Cloudflare plugin which rewrites links in cached pages to match the way its accessed, so if for example you access a page over https you don’t get the version cached with a bunch of http links since that will throw up mixed content warnings in the browser. Other than that WP mostly generates all its links to match whatever protocol you are accessing the current page with. We can make specific pages redirect one way or the other in the future if we want to though... As a startup, site traffic is a metric we track to gouge progress, and so I really need to get to the bottom of if it was the change from http to https that has causes the drop, and if so, what can we do about it? Also, in case it is relevant: the bounce rate is now sky high (ave. 15% to 64% this last week!) Any help is very welcome! Site: https://mobileday.com Thank you!
Web Design | | MobileDay1 -
Does moving Server (IP) affect rankings?
I work for a pretty large company with an established web domain with thousands of pages. We are working on a new website and they talked about moving the site onto a new server. What is the impact ranking wise of going to a new server? Does Google care so long as it's the same domain, or is there some equity lost? Thanks in advance!
Web Design | | ScottOlson0 -
What is the longest you would go back to ressurrect links that should have been 301's?
I have never thought of anything beyond a site that was possibly developed a month or two ago, but an interesting possible client has come along and begs a question. They had their site "redesigned" in April 2014 and it appears whomever did the work did not realize what a 301 was for. Using ahrefs or MajesticSEO, they have gone from roughly 15,000 referring pages to 500 and the time line perfectly intersects the redesign. Sooooo, just wondering if any of you geniuses has ever gone back that far to try and pull off a 301.... I am actually just thinking of a link building / content marketing plan but thought it was an interesting question. Thanks for the help, Robert
Web Design | | RobertFisher1 -
Website Redesign 301 Question
Hey Moz gang, I have a question that I believe I know how I'm going to handle, but just wanted some feedback from the Moz community on best practices. At my company, we're going through a site redesign. At the moment, our site is deeper than it should be with many one-off feature pages. For example, we have a Features page that then links to individual pages for each specific feature. One goal we have set for the redesign is a condensing of the pages in order to make the site more user-friendly, easy to manage and content rich. My question is this. We have a lot of these individual pages that I want to essentially kill and merge into one page. It is okay (best practice) to 301 all of those individual feature specific pages to the single Features page since that is now where all of that content lives?? I want to retain the link juice that those pages have gained over time, but I don't want to get penalized for too many 301's to a single page. Any advice or previous experience would be awesome 🙂 Thanks, Lance
Web Design | | RobinBryant10 -
Will upgrading my dedicated server improve my site speed
hi, at the moment i am concerned about my site speed for www.in2town.co.uk My hosting company is tmd hosting and my package is Intel Atom 330 1MB L2 Cache 1.6GH $159/mo $189/month500GBStorage4GBRAM10TBBandwidthi am looking at increasing this to**$219/mo** $289/month500GBStorage6GBRAM10TBBandwidthcan anyone let me know if this will make a difference to my site speed please
Web Design | | ClaireH-1848860 -
Testing your code and site
I’ve got various WordPress websites with the Share This social plugin for WordPress. I have been using Firebug and http://analyze.websiteoptimization.com/wso to do general checks on the site and the code. And used W3C validator too. Due to the way WordPress appears to work we never seem to be able to get all the firebug/ website optimization tests to pass and the W3C validator passes everything on HTML 5 apart from 7 errors with the Share This social plugin. How do you test your code/websites? Should I stop be a perfectionist and just be happy?
Web Design | | JohnW-UK0 -
SaaS client portal for sharing files, invoicing, messaging?
For lack of a better way to describe what I'm looking for: Can anyone recommend a SaaS application that provides a secure client portal where a company and its clients can upload and share files, send messages, and that allows invoicing and online bill payment? Security is important as some files contain sensitive information, SSL required. I feel like I'm sort of looking for a CRM or something, but not really; and it's almost like base camp, but not quite. Ideas?
Web Design | | jaysan0 -
Is it more beneficial to have internal links without the full file path?
When linking internally in my site is it more beneficial to have links written like, Fast Blenders OR Fast Blenders
Web Design | | tickettoss0