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
-
Website redesign- change of server . What to do with old site? Keep for a while or delete right away?
Hey Mozzers, Two days ago, we redesigned our website and changed the server at the same time to get faster loading times. Here is what we have done. The old site was hosted on ipage, new site with a new design hosted on UPCLOUD. We changed the A record to the new server, uploaded a new site, submitted a new sitemap to Google Search console, 301 redirected all old URLs to new ones, most have changed a bit. Old URLs were ending with " .html "the new ones do not have that at the end. Submitted AMP pages to Google as well. Now here is my question. Should we delete the old site completely from ipage or should we keep it for a while? Google has indexed the new URLs that were created with the redesign, these URLs did not exist on the old site. But it still shows most of the old URLs on SERPs (these are URLs that have been 301 redirected to a new equivalent page) I understand 2 days is not very long for Google to get everything right, but I am not sure what we should do with the old site? Keep it or get rid of it to help Google index the new one only. FYI every single old URL that appears on Google search when clicked on will take you to the right place, we made sure there are no 404s at all. As this is very important to our business and we get most of it from Google I want to make sure we do it right for SEO purposes. The agency that designed the site did not really know the answer to that question, as they do not have SEO specialists. Please help, any input you might have will be greatly appreciated.
Web Design | | Davit19850 -
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 -
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 -
301 redirect on Windows IIS. HELP! (Part 2)
My webmaster's trying (but struggling) to 301-redirect the non.www version of my site to the www version. He's following these instructions given to me in a response to an SEOMoz Private Question (ah, the good old days!). So far he's 301-redirected the homepage but seems stuck on how to do the entire site. Any clues on what he should be doing?
Web Design | | Jeepster0 -
How to verify http://bizdetox.com for google webmaster tools
Hey guys i tried to to make a Preferred Domain choice in webmaster tools, but it is not allowing me to save my choice bec its asking me to verify that i own http://bizdetox.com How do i go about doing that and what are the steps I have already verified www.bizdetox.com
Web Design | | BizDetox0 -
How to Minimize HTTP Requests?
What are the best and simplest programs to minimize HTTP Requests? for JS Images CSS My site is built on a Bitrix CMS
Web Design | | HMCOE0 -
.htaccess on wordpress multisites
Hi Moz fans, I have a site thats uses wordpress multisite. we have a number of sites set as subfolders i.e /en/ /de/ /us/ /fr/ ect. I need to force trailing slashes on each site as I currently have the pages being spidered as /about/ and /about and /iso-9001/ and /iso-9001. I have tried numerous things I have found online in the .htaccess and nothing is working. Can anyone HELP!!
Web Design | | imsmlouis0 -
SEOMoz crawl report shows a duplicate content and duplicate title for these two url's http://freightmonster.com/ and http://freightmonster.com/index.html. How do I fix this?
What page is attached to http://freightmonster.com/ if it is not the index.html ? Should I do a redirect from the index page to something more descriptive?
Web Design | | FreightBoy1