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
-
Has anyone ever tested to see if having an ads.txt file provided any SEO lift?
I know that the ads.txt system is designed to prevent ad fraud and technically has nothing to do with search. That said, the presence of such a file would seem to be an indicator of overall site quality because it would show that a site owner wants to participate in a fraud-free system. Has anyone ever tested that? If so, they don't seem to have published their results. Maybe it's a secret weapon that some pros are using and not sharing?
Web Design | | scodtt0 -
Http to https:Risky?
I recently paid to have my site changed to https but at last minute did not publish it as I got nervous about it! I asked several experienced SEO people and they suggested that as my business is very small, I have a very small budget and it is 100% reliant on search engine hits, that I might take a 10 - 30% hit on ranking and it would take a long time to regain where I was. And that is the best case scenario if we do everything correctly. Apparently even with being very careful, it is easy to make errors which could have some unfortunate consequences. Any opinions?? Is it worth it?
Web Design | | Llanero1 -
We use bigcommerce platform and want to access the bigcommerce server to change the way our product images display
Hi We use bigcommerce and want to chage the way we display multiple images for our products. At the moment in bigcommerce you switch between images by clicking the next image, we want the images to change when we hover the curser over the image. Does anyone know how to do this ? Regards Adrienne
Web Design | | CostumeD0 -
Help with error: Not Found The requested URL /java/backlinker.php was not found on this server.
Hi all, We got this error for almost a month now. Until now we were outsourcing the webdesign and optimization, and now we are doing it in house, and the previous company did not gave us all the information we should know. And we've been trying to find this error and fix it with no result. Have you encounter this issue before? Did anyone found or knows a solution? Also would this affect our website in terms of SEO and in general. Would be very grateful to hear from you. Many thanks. Here is what appears on the bottom of the site( www.manvanlondon.co.uk) Not Found The requested URL /java/backlinker.php was not found on this server. <address>Apache/2.4.7 (Ubuntu) Server at 01adserver.com Port 80</address> <address> </address> <address> </address>
Web Design | | monicapopa0 -
Server performance and loss of rankings
Hi all Wondering if anyone knows how much poor server performance is needed to affect your Google rankings. A few sites of mine were performing fine until about 11am today, since then the site traffic is down about 99% (eeek) at the same time the server was playing up with a server load about 40 - it's 12core, 64ram. I was having database issues at the time too. Surely Google doesn't work that fast in demoting sites for poor performance does it? If not need I need to ponder other reasons why i have no traffic anymore. Thanks, Carl
Web Design | | carl_daedricdigital0 -
301 Redirect from Old Domain to New Domain
I am building a new website and I plan to 301 Redirect my Old Domain (olddomain.com) to a brand new Domain (newdomain.com) in the upcoming months. To do this I was planning to update the htaccess file on both the old and new domains. The htaccess file on the old domain would look to 301 redirect all pages on the old domain to the new domain. The htaccess file on the new domain would detail any specific URL redirects I want to implement (ie. olddomain.com/EXAMPLE/TEST will redirect to newdomain/TEST) - this will ensure link equity is retained and bounce rates are kept at a lower level. Does this sound like the right approach? Also, what do I need to do with the old domain going forward? Do I need to keep this forever in order for the 301 redirect to work or can I eventually just forward the domain to the new one permanently?
Web Design | | DHS_SH0 -
301 Redirect ! Joomla Pages, Already ranking. ( just wanted to change the url
hey guys hope everyone had a new year. I am ranking for a page on my site that i want to ( not specifically move ), but just change the url name: It is too long i think and i want to move it from one portion of my architecture to another menu. I have never physically done a 301 redirect myself, always had someone do it for me. I wanted some pointers. Since it is a fairly new site 4 months old! What are my options. Do i need to 301 redirect the page, if i am changing the Structure and AI of my site, or can i just change the url as is and it will still get ranked? How do i keep that url put delete the page and redirect it ? Sorry its very simple but i wanted to get the communities help to continue on ! Best Wishes HAmpig
Web Design | | BizDetox0 -
How does the toolbar caclulate text to code ratio?
I am seeing some very weird text to code ratios on a competitor site (over 100%) through the Analyze feature on the SEOmoz toolbar. I'm wondering how that's calculated, and what my competitors might be doing to raise that ratio so high artificially. I need to turn in a report on this soon, any help is greatly appreciated!! EHR
Web Design | | EHR0